本文整理汇总了TypeScript中mongoose.connection.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript connection.on方法的具体用法?TypeScript connection.on怎么用?TypeScript connection.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongoose.connection
的用法示例。
在下文中一共展示了connection.on方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: resolve
return new Promise<DatabaseObject>((resolve, reject) => {
mongoose.connect(uri, config)
mongoose.connection.once('connected', () => {
logger.info('database connection: success')
resolve({
alert: AlertModel,
attachment: AttachmentModel,
connection: mongoose.connection,
delivery: DeliveryModel,
logger: logger,
order: OrderModel,
place: PlaceModel,
product: ProductModel,
stock: StockModel,
tokenSalt: config.tokenSalt,
user: UserModel
})
})
mongoose.connection.on('error', (err) => {
logger.error(`database error: ${err}`)
if (! this.isResolved) {
reject(err)
}
})
mongoose.connection.on('disconnected', () => {
logger.info('database connection: ended')
})
})
示例2: connectMongo
private connectMongo() {
let connect = () => mongoose.connect(process.env.MONGO_URL);
mongoose.connection.on('disconnected', connect);
mongoose.connection.on('error', err => {
Logger.errorLog(err);
});
connect();
}
示例3: init
static init():void {
const URL = (process.env.NODE_ENV === 'production') ? process.env.MONGOLAB_URI : dbConst.localhost;
mongoose.connect(URL);
mongoose.connection.on('error', console.error.bind(console, 'An error ocurred with the DB connection: '));
}
示例4: connect
/**
* Mongodb connection
*/
public connect(error, callback) {
Mongoose.connect(this.dburl, this.options);
/** CONNECTION EVENTS */
/** When successfully connected */
Mongoose.connection.on("connected", function() {
Logger.info("Mongoose connection open");
callback();
});
/** If the connection throws an error */
Mongoose.connection.on("error", function(err) {
Logger.info("Mongoose default connection error: " + err);
error(err);
});
}
示例5: _initializeDatabaseConnection
private _initializeDatabaseConnection(test: boolean): void {
winston.info("Initializing database connection");
mongoose.connection.on("open", function(): void {
winston.info("Database connection initialized");
});
mongoose.connection.on("error", function(): void {
winston.error("Unable to connect to the database");
});
if (test) {
mongoose.connect(`mongodb://${config.get("dbConfig.host")}:${config.get("dbConfig.port")}/${config.get("test.dbConfig.dbName")}`);
}
else {
mongoose.connect(`mongodb://${config.get("dbConfig.host")}:${config.get("dbConfig.port")}/${config.get("dbConfig.dbName")}`);
}
}
示例6: disconnect
/**
* Mongodb disconnect
*/
public disconnect(): void {
Mongoose.disconnect((err) => {
Logger.info(err);
});
// Mongoose.connection.close(function() {
// Logger.info("Mongoose connection disconnected");
// callback();
// // process.exit(0);
// });
/** When the connection is disconnected */
Mongoose.connection.on("disconnected", function() {
Logger.info("Mongoose default connection disconnected");
});
}
示例7:
//Handle logout request middleware
app.get('/logout',function(req:any,res){
req.session["isLogin"]=false;
res.render("form",{"message":JSON.stringify('')});
})
//DataBase connection
////mongodb://test:test@ds061345.mongolab.com:61345/portfolioapp
//mongodb://localhost/portfolioapp
var dbUri="mongodb://localhost/portfolioapp";
mongoose.connect(dbUri);
mongoose.connection.on('connected',function() {
console.log('Database connected');
})
mongoose.connection.on('error',function(err) {
console.log(err);
})
//Database Schema
var blogSchema=mongoose.Schema({
"name":{type:String},
"message":{type:String },
"status":{type:Boolean ,default:false},
"sendOn":{type:Date,default:Date.now()}
});
//Database Model
var Blog=mongoose.model('blogs',blogSchema);
示例8: function
import * as mongoose from "mongoose";
let connectionString = process.env.MONGO_URL || "mongodb://db:27017/devopsfun";
mongoose.connect(connectionString);
mongoose.connection.on("error", function() {
console.log("MongoDB Connection Error. Please make sure that MongoDB is running.");
process.exit(1);
});
export default mongoose;
示例9: express
/**
* Create Express server.
*/
const app = express();
/**
* Connect to MongoDB.
*/
(mongoose as any).Promise = global.Promise
mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI)
mongoose.connection.on('error', () => {
// console.log('MongoDB connection error. Please make sure MongoDB is running.')
process.exit()
})
/**
* Express configuration.
*/
app.set('port', process.env.PORT || 3000)
app.set('views', path.join(__dirname, './views'))
app.set('view engine', 'pug')
// app.locals.encodeHTML = (str: string) => {
// return _.escape(str)
// }
app.use(compression())
示例10: function
app.set('view engine','ejs');
//setting middleware
app.use(express.static(path.join(__dirname,'/public')));
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({extended:true}));
app.use(session({
genid: function(req) {
return (Date.now().toString()) // use UUIDs for session IDs
},
secret: '123456789'
}));
//connection verification
mongoose.connection.on('connected',function() {
console.log('Connection status : Database connected');
})
mongoose.connection.on('error',function(err) {
console.log('Connection status : fail \n' +err);
})
var todoSchema=mongoose.Schema({
"email":{type:String, required:true},
"task":{type:String, required:true},
"description":{type:String, required:true},
"createdOn":{type:Date,default:Date.now()}
})
var userSchema=mongoose.Schema({
"username":{type:String , required:true},