Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js mongodb set default safe variable

I am trying to run a Node.js script locally and it's giving me this error message:

========================================================================================
=  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           =
========================================================================================

Here are my variables:

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();

The same scripts runs fine on my live server. It only complanes when I run it locally.

I found this same issue being discussed on github but found no solution. https://github.com/kissjs/node-mongoskin/issues/77

Anyone know what could cause this problem?

Thanks in advance :)

like image 419
Farhan Ahmad Avatar asked Oct 11 '12 18:10

Farhan Ahmad


2 Answers

The following works for me using the 1.1.11 mongo driver:

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

Without the {safe: true} parameter I do get the same warning as you show in your question.

This warning was a very recent addition to the driver; you're probably using an older version of the driver on your server which is why you don't see the warning there.

like image 150
JohnnyHK Avatar answered Oct 13 '22 22:10

JohnnyHK


I got it to work by setting the strict mode to false.

var db = new Db(config.dbName, new Server("127.0.0.1", 27017, {}), {safe: false, strict: false}); 
like image 24
Farhan Ahmad Avatar answered Oct 13 '22 23:10

Farhan Ahmad