本文整理汇总了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}`);
});