【问题标题】:MongoDB write concern when using Mongoose使用 Mongoose 时的 MongoDB 写入问题
【发布时间】:2013-03-15 09:57:39
【问题描述】:

我正在为我的 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 更新到最新版本? npm update mongoose
  • 不幸的是,这没有帮助。

标签: node.js mongodb express mongoose


【解决方案1】:

你想做的是:

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

这将为您提供在 mongo 驱动程序中发生整个显式写入问题之前存在的默认行为。

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

【讨论】:

    【解决方案2】:

    这是因为 connect-mongodb 包。我将其更改为connect-mongo,这解决了问题!

    【讨论】:

      猜你喜欢
      • 2011-10-09
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      • 1970-01-01
      • 2018-04-16
      • 2017-03-12
      • 1970-01-01
      相关资源
      最近更新 更多