J'utilise ce code pour utiliser MongoDB:
========================================================================================
= 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 =
========================================================================================
4 Réponses :
Les documents sont disponibles à p>
http://mongodb.github.com/node-mongodb-native/ p>
Utilisez l'interface Mongoclient à la place p>
http://mongodb.github.com/node- Mongodb-natif / conducteur-articles / mongoclient.html p>
MongoDB vous demande utilement à vous de définir le paramètre de préoccupation d'écriture par défaut (W) dans ses paramètres DB.
Changer cette ligne doit faire le tour p>
var db = new mongo.Db('dbname', server, {w:1});
DB Constructor a trois arguments. "Nom de données", ServerObject, {Paramètres}.
Le message affiché est un avertissement sur la préoccupation de l'écriture et explique les options que vous avez obtenues. P>
var _mongodb = 'MyDataBase';
var db = new mongodb.Db(_mongodb, server, {w:'majority'});
var MongoClient = require('mongodb').MongoClient, Server = require('mongodb').Server;
var mongoClient = new MongoClient(new Server('localhost', 27017));
db = mongoClient.db("mydb");
db.open(function(err, db) {
if(!err) {
console.log("Connected to 'mydb' database");
db.collection('mycollection', {strict:true}, function(err, collection) {
if (err) {
console.log("error...");
}
});
}
});
Ref: http://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html