MongoDB在使用Mongoose时需要注意

我正在为我的Express.js应用程序使用mongoose模块,并且每次启动应用程序时都会收到此错误消息:

 ======================================================================================== = Please ensure that you set the default write concern for the database by setting = = one of the options = = = = w: (value of > -1 or the string 'majority'), where < 1 means = = no write acknowlegement = = journal: true/false, wait for flush to journal before acknowlegement = = fsync: true/false, wait for flush to file system before acknowlegement = = = = For backward compatibility safe is still supported and = = allows values of [true | false | {j:true} | {w:n, wtimeout:n} | {fsync:true}] = = the default value is false which means the driver receives does not = = return the information of the success/error of the insert/update/remove = = = = ex: new Db(new Server('localhost', 27017), {safe:false}) = = = = http://www.mongodb.org/display/DOCS/getLastError+Command = = = = The default of no acknowlegement will change in the very near future = = = = This message will disappear when the default safe is set on the driver Db = ======================================================================================== 

我无法弄清楚如何设置写入问题。 我连接到我的数据库是这样的:

 mongoose.connect('mongodb://localhost/reader') 

你想要做的是:

 mongoose.connect('mongodb://localhost/reader', {db:{safe:false}}) 

这会给你在mongo驱动程序中发生的整个显式写入事件之前存在的默认行为。

更多信息在这里: http : //mongoosejs.com/docs/api.html#index_Mongoose-createConnection

这是因为connect-mongodb包。 我把它改成了connect-mongo ,这个问题就解决了!