本文整理匯總了TypeScript中mongoose.Mongoose.connect方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Mongoose.connect方法的具體用法?TypeScript Mongoose.connect怎麽用?TypeScript Mongoose.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mongoose.Mongoose
的用法示例。
在下文中一共展示了Mongoose.connect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: configureMongoose
export function configureMongoose() {
const mongoose = new Mongoose();
mongoose.connect('mongodb://127.0.0.1/goodsense', function(err) {
if(err) { throw err; }
console.log("Successfully connected to mongodb");
});
return mongoose;
}
示例2: configureMongoose
export function configureMongoose() {
const mongoose = new Mongoose();
mongoose.connect(process.env.MONGODB_URL, function(err) {
if(err) { throw err; }
console.log("Successfully connected to mongodb");
});
return mongoose;
}
示例3: express
import * as express from 'express';
import RestIO from '../../src/index';
import * as mongoose from 'mongoose';
export const app = express();
const port = 3030;
const host = process.env.MONGO_PORT_27017_TCP_ADDR || 'localhost';
let mongoUrl = `mongodb://${host}:${process.env.MONGO_PORT || '27017'}/`;
const db = new mongoose.Mongoose();
mongoUrl += (process.env.DB || 'customResource');
db.connect(mongoUrl);
new RestIO(app, {
db,
resources: `${__dirname}/resources`
});
app.listen(port, () => {
console.log(`Server has started under port: ${port}`);
});