Node.js mongodb设置默认的安全variables
我想本地运行一个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上讨论这个相同的问题,但没有find解决办法。 https://github.com/kissjs/node-mongoskin/issues/77
任何人都知道可能会导致这个问题?
提前致谢 :)
以下为我使用1.1.11 mongo驱动程序:
var db = new Db(Config.dbName, new Server("127.0.0.1", 27017, {}), {safe: true});
如果没有{safe: true}
参数,我会得到和你在问题中显示的一样的警告。
这个警告是司机最近的补充。 你可能在你的服务器上使用了一个老版本的驱动程序,这就是为什么你没有看到那里的警告。
我通过设置strict
模式为false来工作。
var db = new Db(config.dbName, new Server("127.0.0.1", 27017, {}), {safe: false, strict: false});
这对我有用!
var db = new Db((new DbServer('127.0.0.1', 27017), {w:-2,journal:false,fsync:false,safe: false})