13

我正在尝试在本地运行 Node.js 脚本,它给了我这个错误消息:

========================================================================================
=  Please ensure that you set the default safe variable to one of the                  =
=   allowed 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 false will change to true in the near future                         =
=                                                                                      =
=  This message will disappear when the default safe is set on the driver Db           =
========================================================================================

这是我的变量:

var express = require('express');

var mongodb = require('mongodb');
var GridStore = require('mongodb').GridStore;
var Db = require('mongodb').Db;
var Server = require('mongodb').Server;
var db = new Db(Config.dbName, new Server("127.0.0.1", 27017, {}), {});    

var HttpGet = require('./httpGet').HttpGet;
var URL = require('url');

var dbClient = null; // this is initialized when db is opened
var app = module.exports = express();

相同的脚本在我的实时服务器上运行良好。只有当我在本地运行它时它才会崩溃。

我发现在 github 上讨论了同样的问题,但没有找到解决方案。 https://github.com/kissjs/node-mongoskin/issues/77

有谁知道什么可能导致这个问题?

提前致谢 :)

4

3 回答 3

22

以下适用于我使用 1.1.11 mongo 驱动程序:

var db = new Db(Config.dbName, new Server("127.0.0.1", 27017, {}), {safe: true});

如果没有{safe: true}参数,我会收到与您在问题中显示的相同的警告。

此警告是最近添加到驱动程序的;您可能在服务器上使用的是旧版本的驱动程序,这就是您在那里看不到警告的原因。

于 2012-10-11T19:32:47.680 回答
9

我通过将strict模式设置为 false 让它工作。

var db = new Db(config.dbName, new Server("127.0.0.1", 27017, {}), {safe: false, strict: false}); 
于 2012-10-12T20:23:38.143 回答
0

这对我有用!

var db = new Db((new DbServer('127.0.0.1', 27017), {w:-2,journal:false,fsync:false,safe: false})
于 2013-07-10T10:56:47.760 回答