From 7b2f2f3d7fe72fa3291234a59ecf25350ef269a6 Mon Sep 17 00:00:00 2001 From: Christian Kvalheim Date: Thu, 8 Nov 2012 22:55:22 +0100 Subject: [PATCH] cleanup of read preferences --- lib/mongodb/collection.js | 117 +++++----- lib/mongodb/db.js | 179 +++++++-------- test/admin_test.js | 52 ++--- test/aggregation_framework_test.js | 18 +- test/authentication_test.js | 12 +- test/auxilliary/authentication_test.js | 26 +-- test/auxilliary/repl_set_ssl_test.js | 2 +- ...eplicaset_auth_connection_handling_test.js | 4 +- .../replicaset_auth_discovery_test.js | 2 +- test/auxilliary/replicaset_auth_test.js | 12 +- test/auxilliary/sharded_auth_test.js | 2 +- .../single_server_kill_reconnect.js | 12 +- test/auxilliary/ssl_test.js | 4 +- test/collection_test.js | 208 +++++++++--------- test/connect_test.js | 2 +- test/connection_test.js | 22 +- test/cursor_test.js | 140 ++++++------ test/cursorstream_test.js | 18 +- test/custom_pk_test.js | 6 +- test/db_test.js | 148 ++++++------- test/domain_socket_test.js | 6 +- test/error_test.js | 22 +- test/exception_handling_test.js | 2 +- test/find_test.js | 172 +++++++-------- test/geo_search_test.js | 10 +- test/gridstore/grid_store_file_test.js | 22 +- test/gridstore/grid_store_stream_test.js | 6 +- test/gridstore/grid_store_test.js | 46 ++-- test/gridstore/grid_test.js | 8 +- .../gridstore_direct_streaming_test.js | 2 +- test/gridstore/readstream_test.js | 8 +- test/index_test.js | 118 +++++----- test/insert_test.js | 140 ++++++------ test/logging_test.js | 4 +- test/manual_tests/find_modify_break_test.js | 2 +- test/manual_tests/manual_ha_test.js | 4 +- test/manual_tests/manual_larger_queries.js | 4 +- test/manual_tests/manual_lock.js | 4 +- .../replicaset_manual_kill_test.js | 4 +- test/manual_tests/replicaset_test.js | 2 +- test/manual_tests/single_test.js | 4 +- test/manual_tests/tailable_cursor_test.js | 2 +- test/manual_tests/test.js | 2 +- test/map_reduce_test.js | 40 ++-- test/mongo_client_test.js | 2 +- test/mongo_reply_test.js | 2 +- test/multiple_dbs_on_connection_pool_test.js | 18 +- test/objectid_test.js | 14 +- test/raw_test.js | 26 +-- test/reaper_test.js | 124 ----------- test/regexp_test.js | 8 +- test/remove_test.js | 26 +-- test/replicaset/connect_test.js | 36 +-- test/replicaset/count_test.js | 8 +- .../insert_and_query_on_dead_primary_test.js | 6 +- test/replicaset/insert_test.js | 20 +- test/replicaset/map_reduce_test.js | 10 +- test/replicaset/query_secondaries_test.js | 14 +- .../read_preference_replicaset_test.js | 14 +- ...read_preferences_all_levels_legacy_test.js | 14 +- .../read_preferences_all_levels_test.js | 16 +- .../read_preferences_single_test.js | 18 +- test/replicaset/read_preferences_spec.js | 14 +- test/replicaset/reaper_test.js | 2 +- .../secondary_reads_with_primary_down_test.js | 6 +- test/replicaset/shutdown_test.js | 6 +- test/replicaset/strategies_test.js | 12 +- test/replicaset/tags_test.js | 10 +- test/replicaset/two_server_tests.js | 6 +- test/replicaset/url_connection_test.js | 4 +- test/sharded/operations_test.js | 4 +- test/sharded/partial_read_test.js | 2 +- test/sharded/read_preferences_sharded_test.js | 12 +- test/sharded/simple_sharded_setup_test.js | 16 +- test/streaming_test.js | 8 +- test/tools/replica_set_manager.js | 2 +- test/tools/sharded_manager.js | 6 +- test/unicode_test.js | 14 +- test/write_preferences_test.js | 2 +- 79 files changed, 988 insertions(+), 1134 deletions(-) delete mode 100644 test/reaper_test.js diff --git a/lib/mongodb/collection.js b/lib/mongodb/collection.js index 01e8e55aac..a43965d41b 100644 --- a/lib/mongodb/collection.js +++ b/lib/mongodb/collection.js @@ -167,7 +167,7 @@ Collection.prototype.remove = function remove(selector, options, callback) { var self = this; var errorOptions = _getWriteConcern(self, options, callback); // Execute the command, do not add a callback as it's async - if(errorOptions && errorOptions != false) { + if(_hasWriteConcern(errorOptions) && typeof callback == 'function') { // Insert options var commandOptions = {read:false}; // If we have safe set set async to false @@ -195,6 +195,8 @@ Collection.prototype.remove = function remove(selector, options, callback) { callback(null, error[0].n); } }); + } else if(_hasWriteConcern(errorOptions) && callback == null) { + throw new Error("Cannot use a writeConcern without a provided callback"); } else { var result = this.db._executeRemoveCommand(deleteCommand); // If no callback just return @@ -278,7 +280,7 @@ var insertAll = function insertAll (self, docs, options, callback) { , dbName + "." + self.collectionName, true, insertFlags); // Add the documents and decorate them with id's if they have none - for (var index = 0, len = docs.length; index < len; ++index) { + for(var index = 0, len = docs.length; index < len; ++index) { var doc = docs[index]; // Add id to each document if it's not already defined @@ -294,7 +296,7 @@ var insertAll = function insertAll (self, docs, options, callback) { // Default command options var commandOptions = {}; // If safe is defined check for error message - if(errorOptions && errorOptions != false && errorOptions.w != -1 && errorOptions.w != 0) { + if(_hasWriteConcern(errorOptions) && typeof callback == 'function') { // Insert options commandOptions['read'] = false; // If we have safe set set async to false @@ -323,6 +325,8 @@ var insertAll = function insertAll (self, docs, options, callback) { callback(null, docs); } }); + } else if(_hasWriteConcern(errorOptions) && callback == null) { + throw new Error("Cannot use a writeConcern without a provided callback"); } else { var result = self.db._executeInsertCommand(insertCommand, commandOptions, callback); // If no callback just return @@ -361,11 +365,13 @@ Collection.prototype.save = function save(doc, options, callback) { if(!('function' === typeof callback)) callback = null; // Extract the id, if we have one we need to do a update command var id = doc['_id']; + var commandOptions = _getWriteConcern(this, options, callback); if(id) { - this.update({ _id: id }, doc, { upsert: true, safe: _getWriteConcern(this, options, callback) }, callback); + commandOptions.upsert = true; + this.update({ _id: id }, doc, commandOptions, callback); } else { - this.insert(doc, { safe: _getWriteConcern(this, options, callback) }, callback && function (err, docs) { + this.insert(doc, commandOptions, callback && function (err, docs) { if (err) return callback(err, null); if (Array.isArray(docs)) { @@ -429,8 +435,8 @@ Collection.prototype.update = function update(selector, document, options, callb var self = this; // Unpack the error options if any var errorOptions = _getWriteConcern(this, options, callback); - // If we are executing in safe mode or safe both the update and the safe command must happen on the same line - if(errorOptions && errorOptions != false && errorOptions.w != -1 && errorOptions.w != 0) { + // If safe is defined check for error message + if(_hasWriteConcern(errorOptions) && typeof callback == 'function') { // Insert options var commandOptions = {read:false}; // If we have safe set set async to false @@ -459,6 +465,8 @@ Collection.prototype.update = function update(selector, document, options, callb callback(null, error[0].n, error[0]); } }); + } else if(_hasWriteConcern(errorOptions) && callback == null) { + throw new Error("Cannot use a writeConcern without a provided callback"); } else { // Execute update var result = this.db._executeUpdateCommand(updateCommand); @@ -1634,61 +1642,60 @@ Object.defineProperty(Collection.prototype, "hint", { /** * @ignore */ -var _getWriteConcern = function(self, options, callback) { - // Collect errorOptions - var errorOptions = options.safe != null ? options.safe : null; - errorOptions = errorOptions == null && self.opts.safe != null ? self.opts.safe : errorOptions; - errorOptions = errorOptions == null && self.db.safe != null ? self.db.safe : errorOptions; - - // Local options first - if(typeof options.w == 'number' - || typeof options.journal == 'boolean' || typeof options.fsync == 'boolean') { - errorOptions = options; - } else if(typeof self.opts.w == 'number' - || typeof self.opts.journal == 'boolean' || typeof self.opts.fsync == 'boolean') { - errorOptions = self.opts; - } else if(typeof self.db.options.w == 'number' - || typeof self.db.options.journal == 'boolean' || typeof self.db.options.fsync == 'boolean') { - errorOptions = self.db.options; - } - - // Check that we have a valid combination - if(typeof errorOptions.w == 'number' && errorOptions.w < 1 && (errorOptions.journal == true || errorOptions.fsync == true)) { - throw new Error("No acknowlegement using w < 1 cannot be combined with journal:ture or fsync:true"); - } - - // Verify correct behavior of the error conditions - if(errorOptions - && (errorOptions == true || errorOptions.w >= 1) - && typeof callback !== 'function') throw new Error("safe cannot be used without a callback"); +var _hasWriteConcern = function(errorOptions) { + return errorOptions == true + || errorOptions.w > 0 + || errorOptions.w == 'majority' + || errorOptions.journal == true + || errorOptions.fsync == true +} - // Clean up the options ensuring no invalid data is there +/** + * @ignore + */ +var _setWriteConcernHash = function(options) { var finalOptions = {}; - if(errorOptions.w) finalOptions.w = errorOptions.w; - if(errorOptions.fsync) finalOptions.fsync = errorOptions.fsync; - if(errorOptions.journal) finalOptions.journal = errorOptions.journal; - if(errorOptions.wtimeout) finalOptions.wtimeout = errorOptions.wtimeout; - if(errorOptions == true) finalOptions.w = 1; - if(typeof errorOptions == 'object' && Object.keys(errorOptions).length == 0) finalOptions.w = 1; - - // Return the error options + if(options.w != null) finalOptions.w = options.w; + if(options.journal == true) finalOptions.journal = options.journal; + if(options.fsync == true) finalOptions.fsync = options.fsync; + if(options.wtimeout != null) finalOptions.wtimeout = options.wtimeout; return finalOptions; } /** - * Expose. + * @ignore */ -exports.Collection = Collection; - - - - - - - - - - +var _getWriteConcern = function(self, options, callback) { + // Final options + var finalOptions = {w:1}; + // Local options verification + if(options.w != null || typeof options.journal == 'boolean' || typeof options.fsync == 'boolean') { + finalOptions = _setWriteConcernHash(options); + } else if(typeof options.safe == "boolean") { + finalOptions = {w: (options.safe ? 1 : 0)}; + } else if(options.safe != null && typeof options.safe == 'object') { + finalOptions = _setWriteConcernHash(options.safe); + } else if(self.opts.w != null || typeof self.opts.journal == 'boolean' || typeof self.opts.fsync == 'boolean') { + finalOptions = _setWriteConcernHash(self.opts); + } else if(typeof self.opts.safe == "boolean") { + finalOptions = {w: (self.opts.safe ? 1 : 0)}; + } else if(self.db.safe.w != null || typeof self.db.safe.journal == 'boolean' || typeof self.db.safe.fsync == 'boolean') { + finalOptions = _setWriteConcernHash(self.db.safe); + } else if(self.db.options.w != null || typeof self.db.options.journal == 'boolean' || typeof self.db.options.fsync == 'boolean') { + finalOptions = _setWriteConcernHash(self.db.options); + } else if(typeof self.db.safe == "boolean") { + finalOptions = {w: (self.db.safe ? 1 : 0)}; + } + // Ensure we don't have an invalid combination of write concerns + if(finalOptions.w < 1 + && (finalOptions.journal == true) || (finalOptions.fsync == true)) throw new Error("No acknowlegement using w < 1 cannot be combined with journal:ture or fsync:true"); + // Return the options + return finalOptions; +} +/** + * Expose. + */ +exports.Collection = Collection; \ No newline at end of file diff --git a/lib/mongodb/db.js b/lib/mongodb/db.js index ae74892b02..1d89078bfc 100644 --- a/lib/mongodb/db.js +++ b/lib/mongodb/db.js @@ -48,9 +48,6 @@ inherits(CallbackStore, EventEmitter); * - **serializeFunctions** {Boolean, default:false}, serialize functions. * - **raw** {Boolean, default:false}, peform operations using raw bson buffers. * - **recordQueryStats** {Boolean, default:false}, record query statistics during execution. - * - **reaper** {Boolean, default:false}, enables the reaper, timing out calls that never return. - * - **reaperInterval** {Number, default:10000}, number of miliseconds between reaper wakups. - * - **reaperTimeout** {Number, default:30000}, the amount of time before a callback times out. * - **retryMiliSeconds** {Number, default:5000}, number of miliseconds between retries. * - **numberOfRetries** {Number, default:5}, number of retries off connection. * @@ -181,69 +178,14 @@ function Db(databaseName, serverConfig, options) { this.serverConfig.enableRecordQueryStats(true); } - // Reaper enable setting - this.reaperEnabled = this.options.reaper != null ? this.options.reaper : false; - this._lastReaperTimestamp = new Date().getTime(); - // Retry information this.retryMiliSeconds = this.options.retryMiliSeconds != null ? this.options.retryMiliSeconds : 1000; this.numberOfRetries = this.options.numberOfRetries != null ? this.options.numberOfRetries : 60; - // Reaper information - this.reaperInterval = this.options.reaperInterval != null ? this.options.reaperInterval : 10000; - this.reaperTimeout = this.options.reaperTimeout != null ? this.options.reaperTimeout : 30000; - // Set default read preference if any this.readPreference = this.options.readPreference; }; -/** - * The reaper cleans up any callbacks that have not returned inside the space set by - * the parameter reaperTimeout, it will only attempt to reap if the time since last reap - * is bigger or equal to the reaperInterval value - * @ignore - */ -var reaper = function(dbInstance, reaperInterval, reaperTimeout) { - // Get current time, compare to reaper interval - var currentTime = new Date().getTime(); - // Now calculate current time difference to check if it's time to reap - if((currentTime - dbInstance._lastReaperTimestamp) >= reaperInterval) { - // Save current timestamp for next reaper iteration - dbInstance._lastReaperTimestamp = currentTime; - // Get all non-replied to messages - var keys = Object.keys(dbInstance._callBackStore._notReplied); - // Iterate over all callbacks - for(var i = 0; i < keys.length; i++) { - // Fetch the current key - var key = keys[i]; - // Get info element - var info = dbInstance._callBackStore._notReplied[key]; - // If it's timed out let's remove the callback and return an error - if((currentTime - info.start) > reaperTimeout) { - // Cleanup - delete dbInstance._callBackStore._notReplied[key]; - // Perform callback in next Tick - process.nextTick(function() { - if(dbInstance._callBackStore - && dbInstance._callBackStore.listeners(key).length > 0 - && typeof dbInstance._callBackStore.listeners(key)[0] == 'function') { - dbInstance._callBackStore.emit(key, new Error("operation timed out"), null); - } else if(dbInstance._callBackStore - && dbInstance._callBackStore.listeners(key).length > 0) { - console.log("================================================= _callBackStore listener not a function"); - console.dir(dbInstance._callBackStore.listeners(key)); - } - }); - } - } - // Return reaping was done - return true; - } else { - // No reaping done - return false; - } -} - /** * @ignore */ @@ -484,6 +426,7 @@ Db.prototype.collectionNames = function(collectionName, options, callback) { * - **raw** {Boolean, default:false}, perform all operations using raw bson objects. * - **pkFactory** {Object}, object overriding the basic ObjectID primary key generation. * - **readPreference** {String}, the prefered read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). + * - **strict**, (Boolean, default:false) throws and error if collection already exists * * Deprecated Options * - **safe** {true | {w:n, wtimeout:n} | {fsync:true}, default:false}, executes with a getLastError command returning the results of the command on MongoDB. @@ -499,7 +442,8 @@ Db.prototype.collection = function(collectionName, options, callback) { var self = this; if(typeof options === "function") { callback = options; options = {}; } // Execute safe - if(options && options.safe) { + + if(options && (options.strict)) { self.collectionNames(collectionName, function(err, collections) { if(err != null) return callback(err, null); @@ -762,7 +706,6 @@ Db.prototype.addUser = function(username, password, options, callback) { safe = options != null && options['safe'] != null ? options['safe'] : safe; // Ensure it's at least set to safe safe = safe == null ? {w: 1} : safe; - // Use node md5 generator var md5 = crypto.createHash('md5'); // Generate keys used for authentication @@ -778,8 +721,12 @@ Db.prototype.addUser = function(username, password, options, callback) { collection.find({user: username}, {dbName: options['dbName']}).toArray(function(err, documents) { // We got an error (f.ex not authorized) if(err != null) return callback(err, null); + // Add command keys + var commandOptions = safe; + commandOptions.dbName = options['dbName']; + commandOptions.upsert = true; // We have a user, let's update the password or upsert if not - collection.update({user: username},{$set: {user: username, pwd: userPassword}}, {safe:safe, dbName: options['dbName'], upsert:true}, function(err, results) { + collection.update({user: username},{$set: {user: username, pwd: userPassword}}, commandOptions, function(err, results) { if(count == 0 && err) { callback(null, [{user:username, pwd:userPassword}]); } else if(err) { @@ -828,7 +775,11 @@ Db.prototype.removeUser = function(username, options, callback) { var collection = this.collection(DbCommand.SYSTEM_USER_COLLECTION); collection.findOne({user: username}, {dbName: options['dbName']}, function(err, user) { if(user != null) { - collection.remove({user: username}, {safe:safe, dbName: options['dbName']}, function(err, result) { + // Add command keys + var commandOptions = safe; + commandOptions.dbName = options['dbName']; + + collection.remove({user: username}, commandOptions, function(err, result) { callback(err, true); }); } else { @@ -853,6 +804,7 @@ Db.prototype.removeUser = function(username, options, callback) { * - **max** {Number}, the maximum number of documents in the capped collection. * - **autoIndexId** {Boolean, default:false}, create an index on the _id field of the document, not created automatically on capped collections. * - **readPreference** {String}, the prefered read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). + * - **strict**, (Boolean, default:false) throws and error if collection already exists * * Deprecated Options * - **safe** {true | {w:n, wtimeout:n} | {fsync:true}, default:false}, executes with a getLastError command returning the results of the command on MongoDB. @@ -886,7 +838,7 @@ Db.prototype.createCollection = function(collectionName, options, callback) { }); // If the collection exists either throw an exception (if db in safe mode) or return the existing collection - if(found && ((options && options.safe))) { + if(found && options && options.strict) { return callback(new Error("Collection " + collectionName + " already exists. Currently in safe mode."), null); } else if(found){ try { @@ -1147,7 +1099,7 @@ Db.prototype.createIndex = function(collectionName, fieldOrSpec, options, callba var commandOptions = {}; // If we have error conditions set handle them - if(errorOptions && errorOptions != false) { + if(_hasWriteConcern(errorOptions) && typeof callback == 'function') { // Insert options commandOptions['read'] = false; // If we have safe set set async to false @@ -1174,6 +1126,8 @@ Db.prototype.createIndex = function(collectionName, fieldOrSpec, options, callba callback(null, command.documents[0].name); } }); + } else if(_hasWriteConcern(errorOptions) && callback == null) { + throw new Error("Cannot use a writeConcern without a provided callback"); } else { // Execute insert command var result = this._executeInsertCommand(command, commandOptions); @@ -1209,7 +1163,6 @@ Db.prototype.createIndex = function(collectionName, fieldOrSpec, options, callba * Deprecated Options * - **safe** {true | {w:n, wtimeout:n} | {fsync:true}, default:false}, executes with a getLastError command returning the results of the command on MongoDB. * - * * @param {String} collectionName name of the collection to create the index on. * @param {Object} fieldOrSpec fieldOrSpec that defines the index. * @param {Object} [options] additional options during update. @@ -1231,6 +1184,9 @@ Db.prototype.ensureIndex = function(collectionName, fieldOrSpec, options, callba // Get the error options var errorOptions = _getWriteConcern(this, options, callback); + // Make sure we don't try to do a write concern without a callback + if(_hasWriteConcern(errorOptions) && callback == null) + throw new Error("Cannot use a writeConcern without a provided callback"); // Create command var command = DbCommand.createCreateIndexCommand(this, collectionName, fieldOrSpec, options); var index_name = command.documents[0].name; @@ -1243,14 +1199,12 @@ Db.prototype.ensureIndex = function(collectionName, fieldOrSpec, options, callba if(!collectionInfo[index_name]) { // If we have error conditions set handle them - if(errorOptions && errorOptions != false) { + if(_hasWriteConcern(errorOptions) && typeof callback == 'function') { // Insert options commandOptions['read'] = false; // If we have safe set set async to false if(errorOptions == null) commandOptions['async'] = true; - // Set safe option - commandOptions['safe'] = errorOptions; // If we have an error option if(typeof errorOptions == 'object') { var keys = Object.keys(errorOptions); @@ -1259,6 +1213,11 @@ Db.prototype.ensureIndex = function(collectionName, fieldOrSpec, options, callba } } + if(typeof callback === 'function' + && commandOptions.w < 1 && !commandOptions.fsync && !commandOptions.journal) { + commandOptions.w = 1; + } + self._executeInsertCommand(command, commandOptions, function(err, result) { // Only callback if we have one specified if(typeof callback === 'function') { @@ -1597,9 +1556,6 @@ var __executeQueryCommand = function(self, db_command, options, callback) { return callback(connection); } - // Perform reaping of any dead connection - if(self.reaperEnabled) reaper(self, self.reaperInterval, self.reaperTimeout); - // Exhaust Option var exhaust = options.exhaust || false; @@ -1862,7 +1818,7 @@ var __executeInsertCommand = function(self, db_command, options, callback) { } var errorOptions = _getWriteConcern(self, options, callback); - if(errorOptions.w > 0 || errorOptions.journal || errorOptions.fsync) { + if(errorOptions.w > 0 || errorOptions.w == 'majority' || errorOptions.journal || errorOptions.fsync) { // db command is now an array of commands (original command + lastError) db_command = [db_command, DbCommand.createGetLastErrorCommand(safe, self)]; // Register the handler in the data structure @@ -1877,11 +1833,9 @@ var __executeInsertCommand = function(self, db_command, options, callback) { if(connection == null && typeof callback == 'function') return callback(new Error("no primary server found"), null); // Write the message out - connection.write(db_command, function(err) { + connection.write(db_command, function(err) { // Return the callback if it's not a safe operation and the callback is defined if(typeof callback === 'function' && (safe == null || safe == false)) { - // Perform reaping - if(self.reaperEnabled) reaper(self, self.reaperInterval, self.reaperTimeout); // Perform the callback callback(err, null); } else if(typeof callback === 'function') { @@ -2151,43 +2105,58 @@ Object.defineProperty(Db.prototype, "state", { enumerable: true } }); -var _getWriteConcern = function(self, options, callback) { - // Collect errorOptions - var errorOptions = options.safe != null ? options.safe : null; - errorOptions = errorOptions == null && self.safe != null ? self.safe : errorOptions; - - // Local options first - if(typeof options.w == 'number' - || typeof options.journal == 'boolean' || typeof options.fsync == 'boolean') { - errorOptions = options; - } else if(typeof self.options.w == 'number' - || typeof self.options.journal == 'boolean' || typeof self.options.fsync == 'boolean') { - errorOptions = self.opts; - } +/** + * @ignore + */ +var _hasWriteConcern = function(errorOptions) { + return errorOptions == true + || errorOptions.w > 0 + || errorOptions.w == 'majority' + || errorOptions.journal == true + || errorOptions.fsync == true +} - // Check that we have a valid combination - if(typeof errorOptions.w == 'number' && errorOptions.w < 1 && (errorOptions.journal == true || errorOptions.fsync == true)) { - throw new Error("No acknowlegement using w < 1 cannot be combined with journal:ture or fsync:true"); +/** + * @ignore + */ +var _setWriteConcernHash = function(options) { + var finalOptions = {}; + if(options.w != null) finalOptions.w = options.w; + if(options.journal == true) finalOptions.journal = options.journal; + if(options.fsync == true) finalOptions.fsync = options.fsync; + if(options.wtimeout != null) finalOptions.wtimeout = options.wtimeout; + return finalOptions; +} + +/** + * @ignore + */ +var _getWriteConcern = function(self, options, callback) { + // Final options + var finalOptions = {w:1}; + // Local options verification + if(options.w != null || typeof options.journal == 'boolean' || typeof options.fsync == 'boolean') { + finalOptions = _setWriteConcernHash(options); + } else if(options.safe != null && typeof options.safe == 'object') { + finalOptions = _setWriteConcernHash(options.safe); + } else if(typeof options.safe == "boolean") { + finalOptions = {w: (options.safe ? 1 : 0)}; + } else if(self.options.w != null || typeof self.options.journal == 'boolean' || typeof self.options.fsync == 'boolean') { + finalOptions = _setWriteConcernHash(self.options); + } else if(self.safe.w != null || typeof self.safe.journal == 'boolean' || typeof self.safe.fsync == 'boolean') { + finalOptions = _setWriteConcernHash(self.safe); + } else if(typeof self.safe == "boolean") { + finalOptions = {w: (self.safe ? 1 : 0)}; } - // Verify correct behavior of the error conditions - if(errorOptions - && (errorOptions == true || errorOptions.w >= 1) - && typeof callback !== 'function') throw new Error("safe cannot be used without a callback"); + // Ensure we don't have an invalid combination of write concerns + if(finalOptions.w < 1 + && (finalOptions.journal == true) || (finalOptions.fsync == true)) throw new Error("No acknowlegement using w < 1 cannot be combined with journal:ture or fsync:true"); - // Clean up the options ensuring no invalid data is there - var finalOptions = {}; - if(errorOptions.w) finalOptions.w = errorOptions.w; - if(errorOptions.fsync) finalOptions.fsync = errorOptions.fsync; - if(errorOptions.journal) finalOptions.journal = errorOptions.journal; - if(errorOptions.wtimeout) finalOptions.wtimeout = errorOptions.wtimeout; - if(errorOptions == true) finalOptions.w = 1; - if(typeof errorOptions == 'object' && Object.keys(errorOptions).length == 0) finalOptions.w = 1; - // Return the error options + // Return the options return finalOptions; } - /** * Legacy support * diff --git a/test/admin_test.js b/test/admin_test.js index 469850054d..b96a7ec6ae 100644 --- a/test/admin_test.js +++ b/test/admin_test.js @@ -26,7 +26,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -59,12 +59,12 @@ exports.tearDown = function(callback) { * * @ignore */ -exports.shouldCorrectlyCallValidateCollection = function(test) { - var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); +exports.shouldCorrectlyCallValidateCollectionUsingAuthenticatedMode = function(test) { + var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 1, native_parser: (process.env['TEST_NATIVE'] != null)}); fs_client.open(function(err, fs_client) { fs_client.dropDatabase(function(err, done) { fs_client.collection('test', function(err, collection) { - collection.insert({'a':1}, {safe:true}, function(err, doc) { + collection.insert({'a':1}, {w: 1}, function(err, doc) { fs_client.admin(function(err, adminDb) { adminDb.addUser('admin', 'admin', function(err, result) { adminDb.authenticate('admin', 'admin', function(err, replies) { @@ -98,7 +98,7 @@ exports.shouldCorrectlyCallValidateCollection = function(test) { */ exports.shouldCorrectlyAuthenticate = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -111,7 +111,7 @@ exports.shouldCorrectlyAuthenticate = function(test) { // Force the creation of the collection by inserting a document // Collections are not created until the first document is inserted - collection.insert({'a':1}, {safe:true}, function(err, doc) { + collection.insert({'a':1}, {w:1}, function(err, doc) { // Use the admin database for the operation db.admin(function(err, adminDb) { @@ -143,7 +143,7 @@ exports.shouldCorrectlyAuthenticate = function(test) { */ exports.shouldCorrectlyAuthenticate = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -167,7 +167,7 @@ exports.shouldCorrectlyAuthenticate = function(test) { */ exports.shouldCorrectlyAuthenticate = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -208,7 +208,7 @@ exports.shouldCorrectlyAuthenticate = function(test) { */ exports.shouldCorrectlyAuthenticate = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -249,7 +249,7 @@ exports.shouldCorrectlyAuthenticate = function(test) { */ exports.shouldCorrectlySetDefaultProfilingLevel = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -262,7 +262,7 @@ exports.shouldCorrectlySetDefaultProfilingLevel = function(test) { // Force the creation of the collection by inserting a document // Collections are not created until the first document is inserted - collection.insert({'a':1}, {safe:true}, function(err, doc) { + collection.insert({'a':1}, {w: 1}, function(err, doc) { // Use the admin database for the operation db.admin(function(err, adminDb) { @@ -298,7 +298,7 @@ exports.shouldCorrectlySetDefaultProfilingLevel = function(test) { */ exports.shouldCorrectlyChangeProfilingLevel = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -311,7 +311,7 @@ exports.shouldCorrectlyChangeProfilingLevel = function(test) { // Force the creation of the collection by inserting a document // Collections are not created until the first document is inserted - collection.insert({'a':1}, {safe:true}, function(err, doc) { + collection.insert({'a':1}, {w: 1}, function(err, doc) { // Use the admin database for the operation db.admin(function(err, adminDb) { @@ -375,7 +375,7 @@ exports.shouldCorrectlyChangeProfilingLevel = function(test) { */ exports.shouldCorrectlySetAndExtractProfilingInfo = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -388,7 +388,7 @@ exports.shouldCorrectlySetAndExtractProfilingInfo = function(test) { // Force the creation of the collection by inserting a document // Collections are not created until the first document is inserted - collection.insert({'a':1}, {safe:true}, function(doc) { + collection.insert({'a':1}, {w: 1}, function(doc) { // Use the admin database for the operation db.admin(function(err, adminDb) { @@ -439,7 +439,7 @@ exports.shouldCorrectlySetAndExtractProfilingInfo = function(test) { */ exports.shouldCorrectlyCallValidateCollection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -452,7 +452,7 @@ exports.shouldCorrectlyCallValidateCollection = function(test) { // Force the creation of the collection by inserting a document // Collections are not created until the first document is inserted - collection.insert({'a':1}, {safe:true}, function(err, doc) { + collection.insert({'a':1}, {w: 1}, function(err, doc) { // Use the admin database for the operation db.admin(function(err, adminDb) { @@ -494,7 +494,7 @@ exports.shouldCorrectlyCallValidateCollection = function(test) { */ exports.shouldCorrectlyPingTheMongoDbInstance = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -534,7 +534,7 @@ exports.shouldCorrectlyPingTheMongoDbInstance = function(test) { */ exports.shouldCorrectlyUseLogoutFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -575,7 +575,7 @@ exports.shouldCorrectlyUseLogoutFunction = function(test) { */ exports.shouldCorrectlyAddAUserToAdminDb = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -610,7 +610,7 @@ exports.shouldCorrectlyAddAUserToAdminDb = function(test) { */ exports.shouldCorrectlyAddAUserAndRemoveItFromAdminDb = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -655,7 +655,7 @@ exports.shouldCorrectlyAddAUserAndRemoveItFromAdminDb = function(test) { */ exports.shouldCorrectlyListAllAvailableDatabases = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -684,7 +684,7 @@ exports.shouldCorrectlyListAllAvailableDatabases = function(test) { */ exports.shouldCorrectlyRetrieveServerInfo = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -697,7 +697,7 @@ exports.shouldCorrectlyRetrieveServerInfo = function(test) { // Force the creation of the collection by inserting a document // Collections are not created until the first document is inserted - collection.insert({'a':1}, {safe:true}, function(err, doc) { + collection.insert({'a':1}, {w: 1}, function(err, doc) { // Use the admin database for the operation db.admin(function(err, adminDb) { @@ -734,7 +734,7 @@ exports.shouldCorrectlyRetrieveServerInfo = function(test) { */ exports.shouldCorrectlyRetrieveReplSetGetStatus = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -747,7 +747,7 @@ exports.shouldCorrectlyRetrieveReplSetGetStatus = function(test) { // Force the creation of the collection by inserting a document // Collections are not created until the first document is inserted - collection.insert({'a':1}, {safe:true}, function(err, doc) { + collection.insert({'a':1}, {w: 1}, function(err, doc) { // Use the admin database for the operation db.admin(function(err, adminDb) { diff --git a/test/aggregation_framework_test.js b/test/aggregation_framework_test.js index 02054a7fdf..fd2f890436 100644 --- a/test/aggregation_framework_test.js +++ b/test/aggregation_framework_test.js @@ -23,7 +23,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -59,7 +59,7 @@ exports.tearDown = function(callback) { */ exports.shouldCorrectlyExecuteSimpleAggregationPipelineUsingArray = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -78,7 +78,7 @@ exports.shouldCorrectlyExecuteSimpleAggregationPipelineUsingArray = function(tes // Create a collection db.createCollection('shouldCorrectlyExecuteSimpleAggregationPipelineUsingArray', function(err, collection) { // Insert the docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w: 1}, function(err, result) { // Execute aggregate, notice the pipeline is expressed as an Array collection.aggregate([ @@ -120,7 +120,7 @@ exports.shouldCorrectlyExecuteSimpleAggregationPipelineUsingArray = function(tes */ exports.shouldFailWhenExecutingSimpleAggregationPipelineUsingArgumentsNotAnArray = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -139,7 +139,7 @@ exports.shouldFailWhenExecutingSimpleAggregationPipelineUsingArgumentsNotAnArray // Create a collection client.createCollection('shouldCorrectlyExecuteSimpleAggregationPipelineUsingArguments', function(err, collection) { // Insert the docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w: 1}, function(err, result) { // Execute aggregate, notice the pipeline is expressed as function call parameters // instead of an Array. collection.aggregate( @@ -181,7 +181,7 @@ exports.shouldFailWhenExecutingSimpleAggregationPipelineUsingArgumentsNotAnArray */ exports.shouldFailWhenExecutingSimpleAggregationPipelineUsingArgumentsUsingSingleObject = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -200,7 +200,7 @@ exports.shouldFailWhenExecutingSimpleAggregationPipelineUsingArgumentsUsingSingl // Create a collection client.createCollection('shouldCorrectlyExecuteSimpleAggregationPipelineUsingArguments', function(err, collection) { // Insert the docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w: 1}, function(err, result) { // Execute aggregate, notice the pipeline is expressed as function call parameters // instead of an Array. collection.aggregate( @@ -250,7 +250,7 @@ exports.shouldCorrectlyFailAndReturnError = function(test) { // Create a collection client.createCollection('shouldCorrectlyFailAndReturnError', function(err, collection) { // Insert the docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w: 1}, function(err, result) { // Execute aggregate collection.aggregate( { $project : { @@ -291,7 +291,7 @@ exports.shouldCorrectlyFailAndReturnError = function(test) { // // Create a collection // client.createCollection('shouldCorrectlyExecuteAggregationWithExplain', function(err, collection) { // // Insert the docs -// collection.insert(docs, {safe:true}, function(err, result) { +// collection.insert(docs, {w: 1}, function(err, result) { // // Execute aggregate // collection.aggregate( // [{ $project : { diff --git a/test/authentication_test.js b/test/authentication_test.js index 230040b51f..68efc3184a 100644 --- a/test/authentication_test.js +++ b/test/authentication_test.js @@ -22,7 +22,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -82,7 +82,7 @@ exports.shouldCorrectlyReAuthorizeReconnectedConnections = function(test) { var user_name = 'spongebob2'; var password = 'password'; - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize:3, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize:3, ssl:useSSL}), {w: 0, native_parser: (process.env['TEST_NATIVE'] != null)}); p_client.open(function(err, automatic_connect_client) { p_client.authenticate('admin', 'admin', function(err, replies) { test.ok(err instanceof Error); @@ -96,9 +96,9 @@ exports.shouldCorrectlyReAuthorizeReconnectedConnections = function(test) { p_client.serverConfig.close(); p_client.createCollection('shouldCorrectlyReAuthorizeReconnectedConnections', function(err, collection) { - collection.insert({a:1}, {safe:true}, function(err, r) { - collection.insert({a:2}, {safe:true}, function(err, r) { - collection.insert({a:3}, {safe:true}, function(err, r) { + collection.insert({a:1}, {w: 1}, function(err, r) { + collection.insert({a:2}, {w: 1}, function(err, r) { + collection.insert({a:3}, {w: 1}, function(err, r) { collection.count(function(err, count) { test.equal(3, count); p_client.close(); @@ -118,7 +118,7 @@ exports.shouldCorrectlyAddAndRemoveUser = function(test) { var user_name = 'spongebob2'; var password = 'password'; - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {w: 0, native_parser: (process.env['TEST_NATIVE'] != null)}); p_client.open(function(err, automatic_connect_client) { p_client.authenticate('admin', 'admin', function(err, replies) { test.ok(err instanceof Error); diff --git a/test/auxilliary/authentication_test.js b/test/auxilliary/authentication_test.js index ca8b24dfac..adc64dfb60 100644 --- a/test/auxilliary/authentication_test.js +++ b/test/auxilliary/authentication_test.js @@ -14,7 +14,7 @@ var testCase = require('nodeunit').testCase, Step = require("step"); var MONGODB = 'integration_tests'; -var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 1}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); +var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 1}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var serverManager = null; /** @@ -41,9 +41,9 @@ exports.tearDown = function(callback) { exports.shouldCorrectlyAuthenticateWithHorribleBananaCode = function(test) { if(process.env['JENKINS']) return test.done(); - var db1 = new Db('mongo-ruby-test-auth1', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); - var db2 = new Db('mongo-ruby-test-auth2', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); - var admin = new Db('admin', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db1 = new Db('mongo-ruby-test-auth1', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db2 = new Db('mongo-ruby-test-auth2', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); + var admin = new Db('admin', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); serverManager = new ServerManager({auth:false, purgedirectories:true}) serverManager.start(true, function(err, result) { @@ -154,9 +154,9 @@ exports.shouldCorrectlyAuthenticateWithHorribleBananaCode = function(test) { exports.shouldCorrectlyAuthenticate = function(test) { if(process.env['JENKINS']) return test.done(); - var db1 = new Db('mongo-ruby-test-auth1', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); - var db2 = new Db('mongo-ruby-test-auth2', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); - var admin = new Db('admin', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db1 = new Db('mongo-ruby-test-auth1', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db2 = new Db('mongo-ruby-test-auth2', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); + var admin = new Db('admin', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); Step( function bootTheServerWithNoAuth() { @@ -224,11 +224,11 @@ exports.shouldCorrectlyAuthenticate = function(test) { var self = this; db1.collection('stuff', function(err, collection) { - collection.insert({a:2}, {safe:true}, self.parallel()); + collection.insert({a:2}, {w:1}, self.parallel()); }); db2.collection('stuff', function(err, collection) { - collection.insert({a:2}, {safe:true}, self.parallel()); + collection.insert({a:2}, {w:1}, self.parallel()); }); }, @@ -271,11 +271,11 @@ exports.shouldCorrectlyAuthenticate = function(test) { test.equal(1, items.length); db1.collection('stuff', function(err, collection) { - collection.insert({a:2}, {safe:true}, self.parallel()); + collection.insert({a:2}, {w:1}, self.parallel()); }); db2.collection('stuff', function(err, collection) { - collection.insert({a:2}, {safe:true}, self.parallel()); + collection.insert({a:2}, {w:1}, self.parallel()); }); }) }); @@ -292,7 +292,7 @@ exports.shouldCorrectlyAuthenticate = function(test) { function insertShouldFail(err, result) { var self = this; db1.collection('stuff', function(err, collection) { - collection.insert({a:2}, {safe:true}, self.parallel()); + collection.insert({a:2}, {w:1}, self.parallel()); }); }, @@ -304,7 +304,7 @@ exports.shouldCorrectlyAuthenticate = function(test) { function insertShouldFail(err, result) { var self = this; db2.collection('stuff', function(err, collection) { - collection.insert({a:2}, {safe:true}, function(err, result) { + collection.insert({a:2}, {w:1}, function(err, result) { test.ok(err != null); test.done(); // Close all connections diff --git a/test/auxilliary/repl_set_ssl_test.js b/test/auxilliary/repl_set_ssl_test.js index 868e169399..816ec58585 100644 --- a/test/auxilliary/repl_set_ssl_test.js +++ b/test/auxilliary/repl_set_ssl_test.js @@ -59,7 +59,7 @@ exports.shouldCorrectlyConncetToSSLBasedReplicaset = function(test) { // Connect to the replicaset var slaveDb = null; - var db = new Db('foo', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('foo', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, p_db) { test.equal(null, err); test.done(); diff --git a/test/auxilliary/replicaset_auth_connection_handling_test.js b/test/auxilliary/replicaset_auth_connection_handling_test.js index acaf592fd0..50e586b304 100644 --- a/test/auxilliary/replicaset_auth_connection_handling_test.js +++ b/test/auxilliary/replicaset_auth_connection_handling_test.js @@ -57,7 +57,7 @@ exports['Should correctly handle replicaset master stepdown and stepup without l ); // Connect - new Db('replicaset_test_auth', replSet, {safe:false}).open(function(err, db) { + new Db('replicaset_test_auth', replSet, {w:0}).open(function(err, db) { // Just set auths for the manager to handle it correctly RS.setAuths("root", "root"); // Add a user @@ -69,7 +69,7 @@ exports['Should correctly handle replicaset master stepdown and stepup without l test.ok(result); RS.killPrimary(9, function(err, result) { - db.collection('replicaset_test_auth').insert({a:1}, {safe:true}, function(err, result) { + db.collection('replicaset_test_auth').insert({a:1}, {w:1}, function(err, result) { test.equal(null, err); db.close(); diff --git a/test/auxilliary/replicaset_auth_discovery_test.js b/test/auxilliary/replicaset_auth_discovery_test.js index 46366e1c38..b8dc94c710 100644 --- a/test/auxilliary/replicaset_auth_discovery_test.js +++ b/test/auxilliary/replicaset_auth_discovery_test.js @@ -40,7 +40,7 @@ exports.setUp = function(callback) { ); // Connect to the replicaset - var db = new Db('node-native-test', replSet, {safe:false}); + var db = new Db('node-native-test', replSet, {w:0}); db.open(function(err, p_db) { db.addUser("me", "secret", function() { db.close(); diff --git a/test/auxilliary/replicaset_auth_test.js b/test/auxilliary/replicaset_auth_test.js index 833c04f51a..dc7c90a0a2 100644 --- a/test/auxilliary/replicaset_auth_test.js +++ b/test/auxilliary/replicaset_auth_test.js @@ -57,7 +57,7 @@ exports.shouldCorrectlyAuthenticateWithMultipleLoginsAndLogouts = function(test) // Connect to the replicaset var slaveDb = null; - var db = new Db('foo', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('foo', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, p_db) { Step( function addUser() { @@ -133,7 +133,7 @@ exports.shouldCorrectlyAuthenticateWithMultipleLoginsAndLogouts = function(test) test.ok(err != null); slaveDb = new Db('foo', new Server(db.serverConfig.secondaries[0].host - , db.serverConfig.secondaries[0].port, {auto_reconnect: true, poolSize: 1}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null), slave_ok:true}); + , db.serverConfig.secondaries[0].port, {auto_reconnect: true, poolSize: 1}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null), slave_ok:true}); slaveDb.open(function(err, slaveDb) { slaveDb.collection('stuff', function(err, collection) { collection.findOne(self) @@ -178,7 +178,7 @@ exports.shouldCorrectlyAuthenticate = function(test) { // Connect to the replicaset var slaveDb = null; - var db = new Db('foo', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('foo', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, p_db) { Step( function addUser() { @@ -238,7 +238,7 @@ exports.shouldCorrectlyAuthenticateAndEnsureIndex = function(test) { {rs_name:RS.name} ); - var db = new Db(MONGODB, replSet, {safe:false, native_parser: false}); + var db = new Db(MONGODB, replSet, {w:0, native_parser: false}); db.open(function(err, db_p) { if (err){ console.log('ERR:'+err); @@ -300,7 +300,7 @@ exports.shouldCorrectlyAuthenticateAndUseReadPreference = function(test) { {rs_name:RS.name} ); - var db = new Db(MONGODB, replSet, {safe:false, native_parser: false}); + var db = new Db(MONGODB, replSet, {w:0, native_parser: false}); db.open(function(err, db_p) { test.equal(null, err); @@ -310,7 +310,7 @@ exports.shouldCorrectlyAuthenticateAndUseReadPreference = function(test) { db_p.authenticate('test', 'test', function(err, replies) { test.equal(null, err); - db_p.collection('userconfirm2').insert({a:1}, {safe:true}, function(err, result) { + db_p.collection('userconfirm2').insert({a:1}, {w:1}, function(err, result) { test.equal(null, err); db_p.collection('userconfirm2').findOne(function(err, item) { diff --git a/test/auxilliary/sharded_auth_test.js b/test/auxilliary/sharded_auth_test.js index f81f705c2e..997355361d 100644 --- a/test/auxilliary/sharded_auth_test.js +++ b/test/auxilliary/sharded_auth_test.js @@ -70,7 +70,7 @@ exports['Should correctly connect to the mongoses using the connection string an ]); // Connect using the mongos connections - new Db('integration_test_', mongos, {safe:false}).open(function(err, db) { + new Db('integration_test_', mongos, {w:0}).open(function(err, db) { db.admin().addUser("root", "root", function(err, result) { test.equal(null, err); diff --git a/test/auxilliary/single_server_kill_reconnect.js b/test/auxilliary/single_server_kill_reconnect.js index ff1707b4f5..d946886762 100644 --- a/test/auxilliary/single_server_kill_reconnect.js +++ b/test/auxilliary/single_server_kill_reconnect.js @@ -13,7 +13,7 @@ var testCase = require('nodeunit').testCase, Step = require("step"); var MONGODB = 'integration_tests'; -var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 1}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); +var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 1}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var serverManager = null; /** @@ -37,7 +37,7 @@ exports.tearDown = function(callback) { } exports.shouldCorrectlyKeepInsertingDocumentsWhenServerDiesAndComesUp = function(test) { - var db1 = new Db('mongo-ruby-test-single-server', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db1 = new Db('mongo-ruby-test-single-server', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // All inserted docs var docs = []; var errs = []; @@ -94,7 +94,7 @@ exports.shouldCorrectlyKeepInsertingDocumentsWhenServerDiesAndComesUp = function } exports.shouldCorrectlyInsertKillServerFailThenRestartServerAndSucceed = function(test) { - var db = new Db('test-single-server-recovery', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {safe:false, numberOfRetries:3, retryMiliSeconds:500, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('test-single-server-recovery', new Server("127.0.0.1", 27017, {auto_reconnect: true}), {w:0, numberOfRetries:3, retryMiliSeconds:500, native_parser: (process.env['TEST_NATIVE'] != null)}); // All inserted docs var docs = []; var errs = []; @@ -111,14 +111,14 @@ exports.shouldCorrectlyInsertKillServerFailThenRestartServerAndSucceed = functio db.collection('inserts', function(err, collection) { var doc = {timestamp:new Date().getTime(), a:1}; - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.equal(null, err); // Kill server instance serverManager.stop(9, function(err, result) { // Attemp insert (should timeout) var doc = {timestamp:new Date().getTime(), b:1}; - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.ok(err != null); test.equal(null, result); @@ -126,7 +126,7 @@ exports.shouldCorrectlyInsertKillServerFailThenRestartServerAndSucceed = functio serverManager = new ServerManager({auth:false, purgedirectories:false, journal:true}); serverManager.start(true, function() { // Attemp insert again - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { // Fetch the documents collection.find({b:1}).toArray(function(err, items) { test.equal(null, err); diff --git a/test/auxilliary/ssl_test.js b/test/auxilliary/ssl_test.js index 5f86630183..4c32eaa2a9 100644 --- a/test/auxilliary/ssl_test.js +++ b/test/auxilliary/ssl_test.js @@ -38,7 +38,7 @@ exports.tearDown = function(callback) { exports.shouldCorrectlyCommunicateUsingSSLSocket = function(test) { if(process.env['JENKINS']) return test.done(); - var db1 = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, poolSize:4, ssl:ssl}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db1 = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, poolSize:4, ssl:ssl}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // All inserted docs var docs = []; var errs = []; @@ -54,7 +54,7 @@ exports.shouldCorrectlyCommunicateUsingSSLSocket = function(test) { collection.insert([{a:1}, {b:2}, {c:'hello world'}]); collection.insert([{a:1}, {b:2}, {c:'hello world'}]); collection.insert([{a:1}, {b:2}, {c:'hello world'}]); - collection.insert([{a:1}, {b:2}, {c:'hello world'}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2}, {c:'hello world'}], {w:1}, function(err, result) { collection.find({}).toArray(function(err, items) { // test.equal(3, items.length); db.close(); diff --git a/test/collection_test.js b/test/collection_test.js index 2be5da76b8..c31f3601f6 100644 --- a/test/collection_test.js +++ b/test/collection_test.js @@ -26,7 +26,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -62,14 +62,13 @@ exports.tearDown = function(callback) { */ exports.shouldCorrectlySaveASimpleDocument = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { // Fetch the collection db.collection("save_a_simple_document", function(err, collection) { - // Save a document with no safe option collection.save({hello:'world'}); @@ -97,7 +96,7 @@ exports.shouldCorrectlySaveASimpleDocument = function(test) { */ exports.shouldCorrectlySaveASimpleDocumentModifyItAndResaveIt = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -106,7 +105,7 @@ exports.shouldCorrectlySaveASimpleDocumentModifyItAndResaveIt = function(test) { db.collection("save_a_simple_document_modify_it_and_resave_it", function(err, collection) { // Save a document with no safe option - collection.save({hello:'world'}, {safe:true}, function(err, result) { + collection.save({hello:'world'}, {w: 0}, function(err, result) { // Find the saved document collection.findOne({hello:'world'}, function(err, item) { @@ -117,7 +116,7 @@ exports.shouldCorrectlySaveASimpleDocumentModifyItAndResaveIt = function(test) { item['hello2'] = 'world2'; // Save the item with the additional field - collection.save(item, {safe:true}, function(err, result) { + collection.save(item, {w: 1}, function(err, result) { // Find the changed document collection.findOne({hello:'world'}, function(err, item) { @@ -177,10 +176,10 @@ exports.shouldAccessToCollections = function(test) { client.createCollection('test.mario', function(r) { // Insert test documents (creates collections) client.collection('test.spiderman', function(err, spiderman_collection) { - spiderman_collection.insert({foo:5}, {safe:true}, function(err, r) { + spiderman_collection.insert({foo:5}, {w: 1}, function(err, r) { client.collection('test.mario', function(err, mario_collection) { - mario_collection.insert({bar:0}, {safe:true}, function(err, r) { + mario_collection.insert({bar:0}, {w: 1}, function(err, r) { // Assert collections client.collections(function(err, collections) { var found_spiderman = false; @@ -241,7 +240,7 @@ exports.shouldCorrectlyDropCollection = function(test) { */ exports.shouldCorrectlyDropCollectionWithDropFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -292,7 +291,7 @@ exports.shouldCorrectlyRetriveCollectionNames = function(test) { test.ok(found); // Insert a document in an non-existing collection should create the collection client.collection('test_collection_names2', function(err, collection) { - collection.insert({a:1}, {safe:true}, function(err, r) { + collection.insert({a:1}, {w: 1}, function(err, r) { client.collectionNames(function(err, documents) { documents.forEach(function(document) { if(document.name == MONGODB + '.test_collection_names2') found = true; @@ -341,7 +340,7 @@ exports.shouldCorrectlyRetrieveCollectionInfo = function(test) { */ exports.shouldCorrectlyRetriveCollectionOptions = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -372,7 +371,7 @@ exports.shouldCorrectlyRetriveCollectionOptions = function(test) { */ exports.shouldCorrectlyExecuteIsCapped = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -401,17 +400,17 @@ exports.shouldCorrectlyExecuteIsCapped = function(test) { */ exports.shouldCorrectlyExecuteIndexExists = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { // Create a test collection that we are getting the options back from - db.createCollection('test_collection_index_exists', {safe:true}, function(err, collection) { + db.createCollection('test_collection_index_exists', {w: 1}, function(err, collection) { test.equal(null, err); // Create an index on the collection - collection.createIndex('a', {safe:true}, function(err, indexName) { + collection.createIndex('a', {w: 1}, function(err, indexName) { // Let's test to check if a single index exists collection.indexExists("a_1", function(err, result) { @@ -439,17 +438,17 @@ exports.shouldCorrectlyExecuteIndexExists = function(test) { * @ignore */ exports.shouldEnsureStrictAccessCollection = function(test) { - var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {safe:true, native_parser: (process.env['TEST_NATIVE'] != null)}); - test.equal(true, error_client.safe); + var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {w: 1, native_parser: (process.env['TEST_NATIVE'] != null)}); + test.equal(1, error_client.options.w); error_client.open(function(err, error_client) { - error_client.collection('does-not-exist', {safe:true}, function(err, collection) { + error_client.collection('does-not-exist', {strict: true}, function(err, collection) { test.ok(err instanceof Error); test.equal("Collection does-not-exist does not exist. Currently in safe mode.", err.message); }); error_client.createCollection('test_strict_access_collection', function(err, collection) { - error_client.collection('test_strict_access_collection', {safe:true}, function(err, collection) { + error_client.collection('test_strict_access_collection', {w: 1}, function(err, collection) { test.ok(collection instanceof Collection); // Let's close the db error_client.close(); @@ -463,20 +462,20 @@ exports.shouldEnsureStrictAccessCollection = function(test) { * @ignore */ exports.shouldPerformStrictCreateCollection = function(test) { - var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {safe:true, native_parser: (process.env['TEST_NATIVE'] != null)}); - test.equal(true, error_client.safe); + var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {w: 1, native_parser: (process.env['TEST_NATIVE'] != null)}); + // test.equal(true, error_client.safe); error_client.open(function(err, error_client) { error_client.createCollection('test_strict_create_collection', function(err, collection) { test.ok(collection instanceof Collection); // Creating an existing collection should fail - error_client.createCollection('test_strict_create_collection', {safe:true}, function(err, collection) { + error_client.createCollection('test_strict_create_collection', {strict: true}, function(err, collection) { test.ok(err instanceof Error); test.equal("Collection test_strict_create_collection already exists. Currently in safe mode.", err.message); // Switch out of strict mode and try to re-create collection - error_client.createCollection('test_strict_create_collection', {safe:false}, function(err, collection) { + error_client.createCollection('test_strict_create_collection', {strict: false}, function(err, collection) { test.ok(collection instanceof Collection); // Let's close the db @@ -494,35 +493,35 @@ exports.shouldPerformStrictCreateCollection = function(test) { exports.shouldFailToInsertDueToIllegalKeys = function(test) { client.createCollection('test_invalid_key_names', function(err, collection) { // Legal inserts - collection.insert([{'hello':'world'}, {'hello':{'hello':'world'}}], {safe:true}, function(err, r) { + collection.insert([{'hello':'world'}, {'hello':{'hello':'world'}}], {w: 1}, function(err, r) { // Illegal insert for key - collection.insert({'$hello':'world'}, {safe:true}, function(err, doc) { + collection.insert({'$hello':'world'}, {w: 1}, function(err, doc) { test.ok(err instanceof Error); test.equal("key $hello must not start with '$'", err.message); - collection.insert({'hello':{'$hello':'world'}}, {safe:true}, function(err, doc) { + collection.insert({'hello':{'$hello':'world'}}, {w: 1}, function(err, doc) { test.ok(err instanceof Error); test.equal("key $hello must not start with '$'", err.message); - collection.insert({'he$llo':'world'}, {safe:true}, function(err, docs) { + collection.insert({'he$llo':'world'}, {w: 1}, function(err, docs) { test.ok(docs[0].constructor == Object); - collection.insert({'hello':{'hell$o':'world'}}, {safe:true}, function(err, docs) { + collection.insert({'hello':{'hell$o':'world'}}, {w: 1}, function(err, docs) { test.ok(err == null); - collection.insert({'.hello':'world'}, {safe:true}, function(err, doc) { + collection.insert({'.hello':'world'}, {w: 1}, function(err, doc) { test.ok(err instanceof Error); test.equal("key .hello must not contain '.'", err.message); - collection.insert({'hello':{'.hello':'world'}}, {safe:true}, function(err, doc) { + collection.insert({'hello':{'.hello':'world'}}, {w: 1}, function(err, doc) { test.ok(err instanceof Error); test.equal("key .hello must not contain '.'", err.message); - collection.insert({'hello.':'world'}, {safe:true}, function(err, doc) { + collection.insert({'hello.':'world'}, {w: 1}, function(err, doc) { test.ok(err instanceof Error); test.equal("key hello. must not contain '.'", err.message); - collection.insert({'hello':{'hello.':'world'}}, {safe:true}, function(err, doc) { + collection.insert({'hello':{'hello.':'world'}}, {w: 1}, function(err, doc) { test.ok(err instanceof Error); test.equal("key hello. must not contain '.'", err.message); // Let's close the db @@ -588,14 +587,14 @@ exports.shouldCorrectlyCountOnNonExistingCollection = function(test) { exports.shouldCorrectlyExecuteSave = function(test) { client.createCollection('test_save', function(err, collection) { var doc = {'hello':'world'}; - collection.save(doc, {safe:true}, function(err, docs) { + collection.save(doc, {w: 1}, function(err, docs) { test.ok(docs._id instanceof ObjectID || Object.prototype.toString.call(docs._id) === '[object ObjectID]'); collection.count(function(err, count) { test.equal(1, count); doc = docs; - collection.save(doc, {safe:true}, function(err, doc2) { + collection.save(doc, {w: 1}, function(err, doc2) { collection.count(function(err, count) { test.equal(1, count); @@ -605,7 +604,7 @@ exports.shouldCorrectlyExecuteSave = function(test) { doc3.hello = 'mike'; - collection.save(doc3, {safe:true}, function(err, doc4) { + collection.save(doc3, {w: 1}, function(err, doc4) { collection.count(function(err, count) { test.equal(1, count); @@ -613,7 +612,7 @@ exports.shouldCorrectlyExecuteSave = function(test) { test.equal('mike', doc5.hello); // Save another document - collection.save({hello:'world'}, {safe:true}, function(err, doc) { + collection.save({hello:'world'}, {w: 1}, function(err, doc) { collection.count(function(err, count) { test.equal(2, count); // Let's close the db @@ -636,7 +635,7 @@ exports.shouldCorrectlyExecuteSave = function(test) { */ exports.shouldCorrectlySaveDocumentWithLongValue = function(test) { client.createCollection('test_save_long', function(err, collection) { - collection.insert({'x':Long.fromNumber(9223372036854775807)}, {safe:true}, function(err, r) { + collection.insert({'x':Long.fromNumber(9223372036854775807)}, {w: 1}, function(err, r) { collection.findOne(function(err, doc) { test.ok(Long.fromNumber(9223372036854775807).equals(doc.x)); // Let's close the db @@ -652,7 +651,7 @@ exports.shouldCorrectlySaveDocumentWithLongValue = function(test) { exports.shouldSaveObjectThatHasIdButDoesNotExistInCollection = function(test) { client.createCollection('test_save_with_object_that_has_id_but_does_not_actually_exist_in_collection', function(err, collection) { var a = {'_id':'1', 'hello':'world'}; - collection.save(a, {safe:true}, function(err, docs) { + collection.save(a, {w: 1}, function(err, docs) { collection.count(function(err, count) { test.equal(1, count); @@ -660,7 +659,7 @@ exports.shouldSaveObjectThatHasIdButDoesNotExistInCollection = function(test) { test.equal('world', doc.hello); doc.hello = 'mike'; - collection.save(doc, {safe:true}, function(err, doc) { + collection.save(doc, {w: 1}, function(err, doc) { collection.count(function(err, count) { test.equal(1, count); }); @@ -689,7 +688,7 @@ exports.shouldCorrectlyPerformUpsert = function(test) { function test1() { var self = this; - collection.update({"_id":id}, doc, {upsert:true, safe:true}, function(err, result) { + collection.update({"_id":id}, doc, {upsert:true, w: 1}, function(err, result) { test.equal(null, err); test.equal(1, result); @@ -704,7 +703,7 @@ exports.shouldCorrectlyPerformUpsert = function(test) { id = new ObjectID(null) doc = {_id:id, a:2}; - collection.update({"_id":id}, doc, {safe:true, upsert:true}, function(err, result) { + collection.update({"_id":id}, doc, {w: 1, upsert:true}, function(err, result) { test.equal(null, err); test.equal(1, result); @@ -716,7 +715,7 @@ exports.shouldCorrectlyPerformUpsert = function(test) { var self = this; test.equal(2, doc2.a); - collection.update({"_id":id}, doc2, {safe:true, upsert:true}, function(err, result) { + collection.update({"_id":id}, doc2, {w: 1, upsert:true}, function(err, result) { test.equal(null, err); test.equal(1, result); @@ -737,7 +736,7 @@ exports.shouldCorrectlyUpdateWithNoDocs = function(test) { client.createCollection('test_should_correctly_do_update_with_no_docs', function(err, collection) { var id = new ObjectID(null) var doc = {_id:id, a:1}; - collection.update({"_id":id}, doc, {safe:true}, function(err, numberofupdateddocs) { + collection.update({"_id":id}, doc, {w: 1}, function(err, numberofupdateddocs) { test.equal(null, err); test.equal(0, numberofupdateddocs); @@ -754,7 +753,7 @@ exports.shouldCorrectlyUpdateWithNoDocs = function(test) { */ exports.shouldCorrectlyUpdateASimpleDocument = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -763,7 +762,7 @@ exports.shouldCorrectlyUpdateASimpleDocument = function(test) { db.collection('update_a_simple_document', function(err, collection) { // Insert a document, then update it - collection.insert({a:1}, {safe:true}, function(err, doc) { + collection.insert({a:1}, {w: 1}, function(err, doc) { // Update the document with an atomic operator collection.update({a:1}, {$set:{b:2}}); @@ -794,7 +793,7 @@ exports.shouldCorrectlyUpdateASimpleDocument = function(test) { */ exports.shouldCorrectlyUpsertASimpleDocument = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -803,7 +802,7 @@ exports.shouldCorrectlyUpsertASimpleDocument = function(test) { db.collection('update_a_simple_document_upsert', function(err, collection) { // Update the document using an upsert operation, ensuring creation if it does not exist - collection.update({a:1}, {b:2, a:1}, {upsert:true, safe:true}, function(err, result) { + collection.update({a:1}, {b:2, a:1}, {upsert:true, w: 1}, function(err, result) { test.equal(null, err); test.equal(1, result); @@ -829,7 +828,7 @@ exports.shouldCorrectlyUpsertASimpleDocument = function(test) { */ exports.shouldCorrectlyUpdateMultipleDocuments = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -838,10 +837,10 @@ exports.shouldCorrectlyUpdateMultipleDocuments = function(test) { db.collection('update_a_simple_document_multi', function(err, collection) { // Insert a couple of documentations - collection.insert([{a:1, b:1}, {a:1, b:2}], {safe:true}, function(err, result) { + collection.insert([{a:1, b:1}, {a:1, b:2}], {w: 1}, function(err, result) { // Update multiple documents using the multi option - collection.update({a:1}, {$set:{b:0}}, {safe:true, multi:true}, function(err, numberUpdated) { + collection.update({a:1}, {$set:{b:0}}, {w: 1, multi:true}, function(err, numberUpdated) { test.equal(null, err); test.equal(2, numberUpdated); @@ -871,7 +870,7 @@ exports.shouldCorrectlyUpdateMultipleDocuments = function(test) { */ exports.shouldCorrectlyHandleDistinctIndexes = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -881,7 +880,7 @@ exports.shouldCorrectlyHandleDistinctIndexes = function(test) { // Insert documents to perform distinct against collection.insert([{a:0, b:{c:'a'}}, {a:1, b:{c:'b'}}, {a:1, b:{c:'c'}}, - {a:2, b:{c:'a'}}, {a:3}, {a:3}], {safe:true}, function(err, ids) { + {a:2, b:{c:'a'}}, {a:3}, {a:3}], {w: 1}, function(err, ids) { // Peform a distinct query against the a field collection.distinct('a', function(err, docs) { @@ -909,7 +908,7 @@ exports.shouldCorrectlyHandleDistinctIndexes = function(test) { */ exports.shouldCorrectlyHandleDistinctIndexesWithSubQueryFilter = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -919,7 +918,7 @@ exports.shouldCorrectlyHandleDistinctIndexesWithSubQueryFilter = function(test) // Insert documents to perform distinct against collection.insert([{a:0, b:{c:'a'}}, {a:1, b:{c:'b'}}, {a:1, b:{c:'c'}}, - {a:2, b:{c:'a'}}, {a:3}, {a:3}, {a:5, c:1}], {safe:true}, function(err, ids) { + {a:2, b:{c:'a'}}, {a:3}, {a:3}, {a:5, c:1}], {w: 1}, function(err, ids) { // Peform a distinct query with a filter against the documents collection.distinct('a', {c:1}, function(err, docs) { @@ -942,7 +941,7 @@ exports.shouldCorrectlyHandleDistinctIndexesWithSubQueryFilter = function(test) */ exports.shouldCorrectlyDoSimpleCountExamples = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -951,7 +950,7 @@ exports.shouldCorrectlyDoSimpleCountExamples = function(test) { db.createCollection('simple_count_example', function(err, collection) { // Insert documents to perform distinct against - collection.insert([{a:1}, {a:2}, {a:3}, {a:4, b:1}], {safe:true}, function(err, ids) { + collection.insert([{a:1}, {a:2}, {a:3}, {a:4, b:1}], {w: 1}, function(err, ids) { // Perform a total count command collection.count(function(err, count) { @@ -980,17 +979,17 @@ exports.shouldCorrectlyExecuteInsertUpdateDeleteSafeMode = function(test) { test.ok(collection instanceof Collection); test.equal('test_should_execute_insert_update_delete_safe_mode', collection.collectionName); - collection.insert({i:1}, {safe:true}, function(err, ids) { + collection.insert({i:1}, {w: 1}, function(err, ids) { test.equal(1, ids.length); test.ok(ids[0]._id.toHexString().length == 24); // Update the record - collection.update({i:1}, {"$set":{i:2}}, {safe:true}, function(err, result) { + collection.update({i:1}, {"$set":{i:2}}, {w: 1}, function(err, result) { test.equal(null, err); test.equal(1, result); // Remove safely - collection.remove({}, {safe:true}, function(err, result) { + collection.remove({}, {w: 1}, function(err, result) { test.equal(null, err); test.done(); @@ -1004,31 +1003,30 @@ exports.shouldCorrectlyExecuteInsertUpdateDeleteSafeMode = function(test) { * @ignore */ exports.shouldPerformMultipleSaves = function(test) { - client.createCollection("multiple_save_test", function(err, collection) { - var doc = { - name: 'amit', - text: 'some text' - }; - - //insert new user - collection.save(doc, {safe:true}, function(err, r) { - collection.find({}, {name: 1}).limit(1).toArray(function(err, users){ - var user = users[0] - - if(err) { - throw new Error(err) - } else if(user) { - user.pants = 'worn' - - collection.save(user, {safe:true}, function(err, result){ - test.equal(null, err); - test.equal(1, result); - + client.createCollection("multiple_save_test", function(err, collection) { + var doc = { + name: 'amit', + text: 'some text' + }; + + //insert new user + collection.save(doc, {w: 1}, function(err, r) { + collection.find({}, {name: 1}).limit(1).toArray(function(err, users){ + var user = users[0] + + if(err) { + throw new Error(err) + } else if(user) { + user.pants = 'worn' + + collection.save(user, {w: 1}, function(err, result){ + test.equal(null, err); + test.equal(1, result); test.done(); - }) - } - }); - }) + }) + } + }); + }) }); } @@ -1036,11 +1034,11 @@ exports.shouldPerformMultipleSaves = function(test) { * @ignore */ exports.shouldCorrectlySaveDocumentWithNestedArray = function(test) { - var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, ssl:useSSL}), {w: 0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, db) { db.createCollection("save_error_on_save_test", function(err, collection) { // Create unique index for username - collection.createIndex([['username', 1]], {safe:true}, function(err, result) { + collection.createIndex([['username', 1]], {w: 1}, function(err, result) { var doc = { email: 'email@email.com', encrypted_password: 'password', @@ -1054,7 +1052,7 @@ exports.shouldCorrectlySaveDocumentWithNestedArray = function(test) { profile_fields: [], username: 'amit' }; //insert new user - collection.save(doc, {safe:true}, function(err, doc) { + collection.save(doc, {w: 1}, function(err, doc) { collection.find({}).limit(1).toArray(function(err, users) { test.equal(null, err); @@ -1065,7 +1063,7 @@ exports.shouldCorrectlySaveDocumentWithNestedArray = function(test) { test.equal(null, err); // Update again - collection.update({_id:new ObjectID(user._id.toString())}, {friends:user.friends}, {upsert:true, safe:true}, function(err, result) { + collection.update({_id:new ObjectID(user._id.toString())}, {friends:user.friends}, {upsert:true, w: 1}, function(err, result) { test.equal(null, err); test.equal(1, result); @@ -1085,10 +1083,10 @@ exports.shouldCorrectlySaveDocumentWithNestedArray = function(test) { */ exports.shouldPeformCollectionRemoveWithNoCallback = function(test) { client.collection("remove_with_no_callback_bug_test", function(err, collection) { - collection.save({a:1}, {safe:true}, function(){ - collection.save({b:1}, {safe:true}, function(){ - collection.save({c:1}, {safe:true}, function(){ - collection.remove({a:1}, {safe:true}, function() { + collection.save({a:1}, {w: 1}, function(){ + collection.save({b:1}, {w: 1}, function(){ + collection.save({c:1}, {w: 1}, function(){ + collection.remove({a:1}, {w: 1}, function() { // Let's perform a count collection.count(function(err, count) { test.equal(null, err); @@ -1111,7 +1109,7 @@ exports.shouldPeformCollectionRemoveWithNoCallback = function(test) { */ exports.shouldCorrectlyRetriveACollectionsIndexes = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1120,11 +1118,11 @@ exports.shouldCorrectlyRetriveACollectionsIndexes = function(test) { db.createCollection('simple_key_based_distinct', function(err, collection) { // Create a geo 2d index - collection.ensureIndex({loc:"2d"}, {safe:true}, function(err, result) { + collection.ensureIndex({loc:"2d"}, {w: 1}, function(err, result) { test.equal(null, err); // Create a simple single field index - collection.ensureIndex({a:1}, {safe:true}, function(err, result) { + collection.ensureIndex({a:1}, {w: 1}, function(err, result) { test.equal(null, err); // List all of the indexes on the collection @@ -1149,7 +1147,7 @@ exports.shouldCorrectlyRetriveACollectionsIndexes = function(test) { */ exports.shouldCorrectlyReturnACollectionsStats = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w: 0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1158,7 +1156,7 @@ exports.shouldCorrectlyReturnACollectionsStats = function(test) { db.createCollection('collection_stats_test', function(err, collection) { // Insert some documents - collection.insert([{a:1}, {hello:'world'}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {hello:'world'}], {w: 1}, function(err, result) { // Retrieve the statistics for the collection collection.stats(function(err, stats) { @@ -1179,12 +1177,12 @@ exports.shouldThrowErrorOnAttemptingSafeRemoveWithNoCallback = function(test) { client.createCollection('shouldThrowErrorOnAttemptingSafeRemoveWithNoCallback', function(err, collection) { // insert a doc - collection.insert({a:1}, {safe:true}, function(err, result) { + collection.insert({a:1}, {w: 1}, function(err, result) { test.equal(null, err); // attemp a safe remove with no callback (should throw) try { - collection.remove({a:1}, {safe:true}) + collection.remove({a:1}, {w: 1}) test.ok(false); } catch(err) {} @@ -1201,7 +1199,7 @@ exports.shouldThrowErrorOnAttemptingSafeInsertWithNoCallback = function(test) { try { // insert a doc - collection.insert({a:1}, {safe:true}); + collection.insert({a:1}, {w: 1}); test.ok(false); } catch(err) {} @@ -1217,7 +1215,7 @@ exports.shouldThrowErrorOnAttemptingSafeUpdateWithNoCallback = function(test) { try { // insert a doc - collection.update({a:1}, {$set:{b:1}}, {safe:true, upsert:true}); + collection.update({a:1}, {$set:{b:1}}, {w: 1, upsert:true}); test.ok(false); } catch(err) {} @@ -1236,11 +1234,11 @@ exports.shouldCorrectlyCreateTTLCollectionWithIndexUsingEnsureIndex = function(t if(parseInt((result.version.replace(/\./g, ''))) >= 212) { client.createCollection('shouldCorrectlyCreateTTLCollectionWithIndexUsingEnsureIndex', function(err, collection) { - collection.ensureIndex({createdAt:1}, {expireAfterSeconds:1, safe:true}, function(err, result) { + collection.ensureIndex({createdAt:1}, {expireAfterSeconds:1, w: 1}, function(err, result) { test.equal(null, err); // Insert a document with a date - collection.insert({a:1, createdAt:new Date()}, {safe:true}, function(err, result) { + collection.insert({a:1, createdAt:new Date()}, {w: 1}, function(err, result) { test.equal(null, err); collection.indexInformation({full:true}, function(err, indexes) { @@ -1275,11 +1273,11 @@ exports.shouldCorrectlyCreateTTLCollectionWithIndexCreateIndex = function(test) if(parseInt((result.version.replace(/\./g, ''))) >= 212) { client.createCollection('shouldCorrectlyCreateTTLCollectionWithIndexCreateIndex', {}, function(err, collection) { - collection.createIndex({createdAt:1}, {expireAfterSeconds:1, safe:true}, function(err, result) { + collection.createIndex({createdAt:1}, {expireAfterSeconds:1, w: 1}, function(err, result) { test.equal(null, err); // Insert a document with a date - collection.insert({a:1, createdAt:new Date()}, {safe:true}, function(err, result) { + collection.insert({a:1, createdAt:new Date()}, {w: 1}, function(err, result) { test.equal(null, err); collection.indexInformation({full:true}, function(err, indexes) { @@ -1309,7 +1307,7 @@ exports.shouldCorrectlyCreateTTLCollectionWithIndexCreateIndex = function(test) exports.shouldCorrectlyReadBackDocumentWithNull = function(test) { client.createCollection('shouldCorrectlyReadBackDocumentWithNull', {}, function(err, collection) { // Insert a document with a date - collection.insert({test:null}, {safe:true}, function(err, result) { + collection.insert({test:null}, {w: 1}, function(err, result) { test.equal(null, err); collection.findOne(function(err, item) { diff --git a/test/connect_test.js b/test/connect_test.js index 6fded4c041..9a936a4924 100644 --- a/test/connect_test.js +++ b/test/connect_test.js @@ -25,7 +25,7 @@ function connectionTester(test, testName, callback) { db.collection(testName, function(err, collection) { test.equal(err, null); var doc = {foo:123}; - collection.insert({foo:123}, {safe:true}, function(err, docs) { + collection.insert({foo:123}, {w:1}, function(err, docs) { test.equal(err, null); db.dropDatabase(function(err, done) { db.close(); diff --git a/test/connection_test.js b/test/connection_test.js index ed668bdfc8..42b247329e 100644 --- a/test/connection_test.js +++ b/test/connection_test.js @@ -24,7 +24,7 @@ function connectionTester(test, testName, callback) { db.collection(testName, function(err, collection) { test.equal(err, null); var doc = {foo:123}; - collection.insert({foo:123}, {safe:true}, function(err, docs) { + collection.insert({foo:123}, {w:1}, function(err, docs) { test.equal(err, null); db.dropDatabase(function(err, done) { test.equal(err, null); @@ -44,7 +44,7 @@ function connectionTester(test, testName, callback) { */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -75,8 +75,8 @@ exports.shouldThrowErrorDueToSharedConnectionUsage = function(test) { var server = new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}); try { - var db = new Db(MONGODB, server, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); - var db1 = new Db(MONGODB, server, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, server, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db1 = new Db(MONGODB, server, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); } catch(err) { if (db) db.close(); if (db1) db1.close(); @@ -126,7 +126,7 @@ exports.shouldCorrectlyReconnectOnNonExistingServer = function(test) { var serverManager = new ServerManager({auth:false, purgedirectories:true, journal:true}) // Kill the server serverManager.killAll(function() { - var _client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var _client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); _client.open(function(err, __client) { test.ok(err != null); // Restart the server @@ -144,7 +144,7 @@ exports.shouldCorrectlyReconnectOnNonExistingServer = function(test) { exports.shouldCorrectlyOpenCloseAndOpenAgain = function(test) { var server = new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}); - var db = new Db(MONGODB, server, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, server, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, db){ test.equal(null, err); @@ -162,7 +162,7 @@ exports.shouldCorrectlyOpenCloseAndOpenAgain = function(test) { } exports.testCloseNoCallback = function(test) { - var db = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(connectionTester(test, 'testCloseNoCallback', function() { var dbCloseCount = 0, connectionCloseCount = 0, poolCloseCount = 0; // Ensure no close events are fired as we are closing the connection specifically @@ -180,7 +180,7 @@ exports.testCloseNoCallback = function(test) { } exports.testCloseWithCallback = function(test) { - var db = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}),{safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}),{w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(connectionTester(test, 'testCloseWithCallback', function() { var dbCloseCount = 0, connectionCloseCount = 0, poolCloseCount = 0; // Ensure no close events are fired as we are closing the connection specifically @@ -203,13 +203,13 @@ exports.testCloseWithCallback = function(test) { } exports.testShouldCorrectlyCloseOnUnopedConnection = function(test) { - var db = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}),{safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}),{w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.close(); test.done(); } exports.testConnectUsingDefaultHostAndPort = function(test) { - var db = new Db(MONGODB, new Server("127.0.0.1", mongodb.Connection.DEFAULT_PORT, {auto_reconnect: true, poolSize: 4, ssl:useSSL}),{safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server("127.0.0.1", mongodb.Connection.DEFAULT_PORT, {auto_reconnect: true, poolSize: 4, ssl:useSSL}),{w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, db) { test.equal(null, err); test.done(); @@ -218,7 +218,7 @@ exports.testConnectUsingDefaultHostAndPort = function(test) { } exports.testConnectUsingSocketOptions = function(test) { - var db = new Db(MONGODB, new Server("127.0.0.1", mongodb.Connection.DEFAULT_PORT, {auto_reconnect: true, poolSize: 4, socketOptions:{keepAlive:100}, ssl:useSSL}),{safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server("127.0.0.1", mongodb.Connection.DEFAULT_PORT, {auto_reconnect: true, poolSize: 4, socketOptions:{keepAlive:100}, ssl:useSSL}),{w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, db) { test.equal(null, err); test.equal(100, db.serverConfig.checkoutWriter().socketOptions.keepAlive) diff --git a/test/cursor_test.js b/test/cursor_test.js index 19669981ee..b7b5f3dffd 100644 --- a/test/cursor_test.js +++ b/test/cursor_test.js @@ -25,7 +25,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -60,7 +60,7 @@ exports.tearDown = function(callback) { */ exports.shouldCorrectlyExecuteToArray = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -69,7 +69,7 @@ exports.shouldCorrectlyExecuteToArray = function(test) { db.createCollection('test_array', function(err, collection) { // Insert a test document - collection.insert({'b':[1, 2, 3]}, {safe:true}, function(err, ids) { + collection.insert({'b':[1, 2, 3]}, {w:1}, function(err, ids) { // Retrieve all the documents in the collection collection.find().toArray(function(err, documents) { @@ -91,7 +91,7 @@ exports.shouldCorrectlyExecuteToArray = function(test) { exports.shouldCorrectlyExecuteToArrayAndFailOnFurtherCursorAccess = function(test) { client.createCollection('test_to_a', function(err, collection) { test.ok(collection instanceof Collection); - collection.insert({'a':1}, {safe:true}, function(err, ids) { + collection.insert({'a':1}, {w:1}, function(err, ids) { var cursor = collection.find({}); cursor.toArray(function(err, items) { // Should fail if called again (cursor should be closed) @@ -121,7 +121,7 @@ exports.shouldCorrectlyExecuteToArrayAndFailOnFurtherCursorAccess = function(tes */ exports.shouldCorrectlyFailToArrayDueToFinishedEachOperation = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -132,7 +132,7 @@ exports.shouldCorrectlyFailToArrayDueToFinishedEachOperation = function(test) { test.ok(collection instanceof Collection); // Insert a document in the collection - collection.insert({'a':1}, {safe:true}, function(err, ids) { + collection.insert({'a':1}, {w:1}, function(err, ids) { // Grab a cursor var cursor = collection.find(); @@ -164,7 +164,7 @@ exports.shouldCorrectlyFailToArrayDueToFinishedEachOperation = function(test) { */ exports.shouldCorrectlyExecuteCursorExplain = function(test) { client.createCollection('test_explain', function(err, collection) { - collection.insert({'a':1}, {safe:true}, function(err, r) { + collection.insert({'a':1}, {w:1}, function(err, r) { collection.find({'a':1}).explain(function(err, explaination) { test.ok(explaination.cursor != null); test.ok(explaination.n.constructor == Number); @@ -192,7 +192,7 @@ exports.shouldCorrectlyExecuteCursorCount = function(test) { var group = this.group(); for(var i = 0; i < 10; i++) { - collection.insert({'x':i}, {safe:true}, group()); + collection.insert({'x':i}, {w:1}, group()); } }, @@ -246,7 +246,7 @@ exports.shouldCorrectlyExecuteSortOnCursor = function(test) { var group = this.group(); for(var i = 0; i < 5; i++) { - collection.insert({'a':i}, {safe:true}, group()); + collection.insert({'a':i}, {w:1}, group()); } }, @@ -316,7 +316,7 @@ exports.shouldCorrectlyThrowErrorOnToArrayWhenMissingCallback = function(test) { var group = this.group(); for(var i = 0; i < 2; i++) { - collection.save({'x':1}, {safe:true}, group()); + collection.save({'x':1}, {w:1}, group()); } }, @@ -343,7 +343,7 @@ exports.shouldThrowErrorOnEachWhenMissingCallback = function(test) { var group = this.group(); for(var i = 0; i < 2; i++) { - collection.save({'x':1}, {safe:true}, group()); + collection.save({'x':1}, {w:1}, group()); } }, @@ -370,7 +370,7 @@ exports.shouldCorrectlyHandleLimitOnCursor = function(test) { var group = this.group(); for(var i = 0; i < 10; i++) { - collection.save({'x':1}, {safe:true}, group()); + collection.save({'x':1}, {w:1}, group()); } }, @@ -400,7 +400,7 @@ exports.shouldCorrectlyHandleNegativeOneLimitOnCursor = function(test) { var group = this.group(); for(var i = 0; i < 10; i++) { - collection.save({'x':1}, {safe:true}, group()); + collection.save({'x':1}, {w:1}, group()); } }, @@ -426,7 +426,7 @@ exports.shouldCorrectlyHandleAnyNegativeLimitOnCursor = function(test) { var group = this.group(); for(var i = 0; i < 10; i++) { - collection.save({'x':1}, {safe:true}, group()); + collection.save({'x':1}, {w:1}, group()); } }, @@ -447,7 +447,7 @@ exports.shouldCorrectlyHandleAnyNegativeLimitOnCursor = function(test) { */ exports.shouldCorrectlyReturnErrorsOnIllegalLimitValues = function(test) { client.createCollection('test_limit_exceptions', function(err, collection) { - collection.insert({'a':1}, {safe:true}, function(err, docs) {}); + collection.insert({'a':1}, {w:1}, function(err, docs) {}); collection.find(function(err, cursor) { cursor.limit('not-an-integer', function(err, cursor) { test.ok(err instanceof Error); @@ -508,7 +508,7 @@ exports.shouldCorrectlySkipRecordsOnCursor = function(test) { var group = this.group(); for(var i = 0; i < 10; i++) { - collection.insert({'x':i}, {safe:true}, group()); + collection.insert({'x':i}, {w:1}, group()); } }, @@ -551,7 +551,7 @@ exports.shouldCorrectlySkipRecordsOnCursor = function(test) { */ exports.shouldCorrectlyReturnErrorsOnIllegalSkipValues = function(test) { client.createCollection('test_skip_exceptions', function(err, collection) { - collection.insert({'a':1}, {safe:true}, function(err, docs) {}); + collection.insert({'a':1}, {w:1}, function(err, docs) {}); collection.find().skip('not-an-integer', function(err, cursor) { test.ok(err instanceof Error); test.equal("skip requires an integer", err.message); @@ -583,7 +583,7 @@ exports.shouldCorrectlyReturnErrorsOnIllegalSkipValues = function(test) { */ exports.shouldReturnErrorsOnIllegalBatchSizes = function(test) { client.createCollection('test_batchSize_exceptions', function(err, collection) { - collection.insert({'a':1}, {safe:true}, function(err, docs) {}); + collection.insert({'a':1}, {w:1}, function(err, docs) {}); var cursor = collection.find(); cursor.batchSize('not-an-integer', function(err, cursor) { test.ok(err instanceof Error); @@ -646,7 +646,7 @@ exports.shouldCorrectlyHandleChangesInBatchSizes = function(test) { docs.push({'a':i}); } - collection.insert(docs, {safe:true}, function() { + collection.insert(docs, {w:1}, function() { collection.find({}, {batchSize : batchSize}, function(err, cursor) { //1st cursor.nextObject(function(err, items) { @@ -715,7 +715,7 @@ exports.shouldCorrectlyHandleBatchSize = function(test) { docs.push({'a':i}); } - collection.insert(docs, {safe:true}, function() { + collection.insert(docs, {w:1}, function() { collection.find({}, {batchSize : batchSize}, function(err, cursor) { //1st cursor.nextObject(function(err, items) { @@ -767,7 +767,7 @@ exports.shouldHandleWhenLimitBiggerThanBatchSize = function(test) { docs.push({'a':i}); } - collection.insert(docs, {safe:true}, function() { + collection.insert(docs, {w:1}, function() { var cursor = collection.find({}, {batchSize : batchSize, limit : limit}); //1st cursor.nextObject(function(err, items) { @@ -814,7 +814,7 @@ exports.shouldHandleLimitLessThanBatchSize = function(test) { docs.push({'a':i}); } - collection.insert(docs, {safe:true}, function() { + collection.insert(docs, {w:1}, function() { var cursor = collection.find({}, {batchSize : batchSize, limit : limit}); //1st cursor.nextObject(function(err, items) { @@ -848,7 +848,7 @@ exports.shouldHandleSkipLimitChaining = function(test) { var group = this.group(); for(var i = 0; i < 10; i++) { - collection.insert({'x':1}, {safe:true}, group()); + collection.insert({'x':1}, {w:1}, group()); } }, @@ -888,7 +888,7 @@ exports.shouldCorrectlyHandleLimitSkipChainingInline = function(test) { var group = this.group(); for(var i = 0; i < 10; i++) { - collection.insert({'x':1}, {safe:true}, group()); + collection.insert({'x':1}, {w:1}, group()); } }, @@ -944,7 +944,7 @@ exports.shouldCorrectlyRefillViaGetMoreCommand = function(test) { var group = this.group(); for(var i = 0; i < COUNT; i++) { - collection.save({'a': i}, {safe:true}, group()); + collection.save({'a': i}, {w:1}, group()); } }, @@ -1001,7 +1001,7 @@ exports.shouldCorrectlyRefillViaGetMoreAlternativeCollection = function(test) { var group = this.group(); for(var i = 0; i < 1000; i++) { - collection.save({'a': i}, {safe:true}, group()); + collection.save({'a': i}, {w:1}, group()); } }, @@ -1052,7 +1052,7 @@ exports.shouldCorrectlyRefillViaGetMoreAlternativeCollection = function(test) { */ exports.shouldCloseCursorAfterQueryHasBeenSent = function(test) { client.createCollection('test_close_after_query_sent', function(err, collection) { - collection.insert({'a':1}, {safe:true}, function(err, r) { + collection.insert({'a':1}, {w:1}, function(err, r) { var cursor = collection.find({'a':1}); cursor.nextObject(function(err, item) { cursor.close(function(err, cursor) { @@ -1071,7 +1071,7 @@ exports.shouldCloseCursorAfterQueryHasBeenSent = function(test) { */ exports.shouldCorrectlyExecuteCursorCountWithFields = function(test) { client.createCollection('test_count_with_fields', function(err, collection) { - collection.save({'x':1, 'a':2}, {safe:true}, function(err, doc) { + collection.save({'x':1, 'a':2}, {w:1}, function(err, doc) { collection.find({}, {'fields':['a']}).toArray(function(err, items) { test.equal(1, items.length); test.equal(2, items[0].a); @@ -1093,7 +1093,7 @@ exports.shouldCorrectlyExecuteCursorCountWithFields = function(test) { */ exports.shouldCorrectlyCountWithFieldsUsingExclude = function(test) { client.createCollection('test_count_with_fields_using_exclude', function(err, collection) { - collection.save({'x':1, 'a':2}, {safe:true}, function(err, doc) { + collection.save({'x':1, 'a':2}, {w:1}, function(err, doc) { collection.find({}, {'fields':{'x':0}}).toArray(function(err, items) { test.equal(1, items.length); test.equal(2, items[0].a); @@ -1121,7 +1121,7 @@ exports.shouldCorrectlyExecuteEnsureIndexWithNoCallback = function(test) { // ensure index of createdAt index collection.ensureIndex({createdAt:1}) // insert all docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); // Find with sort @@ -1153,7 +1153,7 @@ exports.shouldCorrectlyInsert5000RecordsWithDateAndSortCorrectlyWithIndex = func test.equal(null, err); // insert all docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); // Find with sort @@ -1175,7 +1175,7 @@ exports.shouldCorrectlyInsert5000RecordsWithDateAndSortCorrectlyWithIndex = func */ exports['Should correctly rewind and restart cursor'] = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1192,7 +1192,7 @@ exports['Should correctly rewind and restart cursor'] = function(test) { test.equal(null, err); // insert all docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); // Grab a cursor using the find @@ -1233,7 +1233,7 @@ exports['Should correctly execute count on cursor'] = function(test) { test.equal(null, err); // insert all docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); var total = 0; // Create a cursor for the content @@ -1272,7 +1272,7 @@ exports['should be able to stream documents'] = function(test) { test.equal(null, err); // insert all docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); var paused = 0 @@ -1345,7 +1345,7 @@ exports['immediately destroying a stream prevents the query from executing'] = f test.equal(null, err); // insert all docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); var stream = collection.find().stream(); @@ -1381,7 +1381,7 @@ exports['destroying a stream stops it'] = function(test) { for (var ii = 0; ii < 10; ++ii) docs.push({ b: ii+1 }); // insert all docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); var finished = 0 @@ -1423,7 +1423,7 @@ exports['destroying a stream stops it'] = function(test) { * @api private */ exports['cursor stream errors']= function(test) { - var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { test.equal(null, err); @@ -1434,7 +1434,7 @@ exports['cursor stream errors']= function(test) { for (var ii = 0; ii < 10; ++ii) docs.push({ b: ii+1 }); // insert all docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); var finished = 0 @@ -1487,7 +1487,7 @@ exports['cursor stream pipe']= function(test) { }); // insert all docs - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); var filename = '/tmp/_nodemongodbnative_stream_out.txt' @@ -1533,7 +1533,7 @@ exports['cursor stream pipe']= function(test) { */ exports.shouldCorrectlyUseCursorCountFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1543,7 +1543,7 @@ exports.shouldCorrectlyUseCursorCountFunction = function(test) { test.equal(null, err); // Insert some docs - collection.insert([{a:1}, {a:2}], {safe:true}, function(err, docs) { + collection.insert([{a:1}, {a:2}], {w:1}, function(err, docs) { test.equal(null, err); // Do a find and get the cursor count @@ -1568,7 +1568,7 @@ exports.shouldCorrectlyUseCursorCountFunction = function(test) { */ exports.shouldCorrectlyPeformSimpleSorts = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1578,7 +1578,7 @@ exports.shouldCorrectlyPeformSimpleSorts = function(test) { test.equal(null, err); // Insert some documents we can sort on - collection.insert([{a:1}, {a:2}, {a:3}], {safe:true}, function(err, docs) { + collection.insert([{a:1}, {a:2}, {a:3}], {w:1}, function(err, docs) { test.equal(null, err); // Do normal ascending sort @@ -1609,7 +1609,7 @@ exports.shouldCorrectlyPeformSimpleSorts = function(test) { */ exports.shouldCorrectlyPeformLimitOnCursor = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1619,7 +1619,7 @@ exports.shouldCorrectlyPeformLimitOnCursor = function(test) { test.equal(null, err); // Insert some documents we can sort on - collection.insert([{a:1}, {a:2}, {a:3}], {safe:true}, function(err, docs) { + collection.insert([{a:1}, {a:2}, {a:3}], {w:1}, function(err, docs) { test.equal(null, err); // Limit to only one document returned @@ -1644,7 +1644,7 @@ exports.shouldCorrectlyPeformLimitOnCursor = function(test) { */ exports.shouldCorrectlyPeformSkipOnCursor = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1654,7 +1654,7 @@ exports.shouldCorrectlyPeformSkipOnCursor = function(test) { test.equal(null, err); // Insert some documents we can sort on - collection.insert([{a:1}, {a:2}, {a:3}], {safe:true}, function(err, docs) { + collection.insert([{a:1}, {a:2}, {a:3}], {w:1}, function(err, docs) { test.equal(null, err); // Skip one document @@ -1680,7 +1680,7 @@ exports.shouldCorrectlyPeformSkipOnCursor = function(test) { */ exports.shouldCorrectlyPeformBatchSizeOnCursor = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1690,7 +1690,7 @@ exports.shouldCorrectlyPeformBatchSizeOnCursor = function(test) { test.equal(null, err); // Insert some documents we can sort on - collection.insert([{a:1}, {a:2}, {a:3}], {safe:true}, function(err, docs) { + collection.insert([{a:1}, {a:2}, {a:3}], {w:1}, function(err, docs) { test.equal(null, err); // Do normal ascending sort @@ -1715,7 +1715,7 @@ exports.shouldCorrectlyPeformBatchSizeOnCursor = function(test) { */ exports.shouldCorrectlyPeformNextObjectOnCursor = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1725,7 +1725,7 @@ exports.shouldCorrectlyPeformNextObjectOnCursor = function(test) { test.equal(null, err); // Insert some documents we can sort on - collection.insert([{a:1}, {a:2}, {a:3}], {safe:true}, function(err, docs) { + collection.insert([{a:1}, {a:2}, {a:3}], {w:1}, function(err, docs) { test.equal(null, err); // Do normal ascending sort @@ -1750,7 +1750,7 @@ exports.shouldCorrectlyPeformNextObjectOnCursor = function(test) { */ exports.shouldCorrectlyPeformSimpleExplainCursor = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1760,7 +1760,7 @@ exports.shouldCorrectlyPeformSimpleExplainCursor = function(test) { test.equal(null, err); // Insert some documents we can sort on - collection.insert([{a:1}, {a:2}, {a:3}], {safe:true}, function(err, docs) { + collection.insert([{a:1}, {a:2}, {a:3}], {w:1}, function(err, docs) { test.equal(null, err); // Do normal ascending sort @@ -1784,7 +1784,7 @@ exports.shouldCorrectlyPeformSimpleExplainCursor = function(test) { */ exports.shouldStreamDocumentsUsingTheStreamRecords = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1800,7 +1800,7 @@ exports.shouldStreamDocumentsUsingTheStreamRecords = function(test) { test.equal(null, err); // Insert documents into collection - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { // Peform a find to get a cursor var stream = collection.find().streamRecords({fetchSize:1000}); @@ -1827,7 +1827,7 @@ exports.shouldStreamDocumentsUsingTheStreamRecords = function(test) { */ exports.shouldStreamDocumentsUsingTheStreamFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1843,7 +1843,7 @@ exports.shouldStreamDocumentsUsingTheStreamFunction = function(test) { test.equal(null, err); // Insert documents into collection - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { // Peform a find to get a cursor var stream = collection.find().stream(); @@ -1870,7 +1870,7 @@ exports.shouldStreamDocumentsUsingTheStreamFunction = function(test) { */ exports.shouldStreamDocumentsUsingTheCloseFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1886,7 +1886,7 @@ exports.shouldStreamDocumentsUsingTheCloseFunction = function(test) { test.equal(null, err); // Insert documents into collection - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { // Peform a find to get a cursor var cursor = collection.find(); @@ -1916,7 +1916,7 @@ exports.shouldStreamDocumentsUsingTheCloseFunction = function(test) { */ exports.shouldStreamDocumentsUsingTheIsCloseFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1932,7 +1932,7 @@ exports.shouldStreamDocumentsUsingTheIsCloseFunction = function(test) { test.equal(null, err); // Insert documents into collection - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { // Peform a find to get a cursor var cursor = collection.find(); @@ -1960,7 +1960,7 @@ exports.shouldStreamDocumentsUsingTheIsCloseFunction = function(test) { exports.shouldCloseDeadTailableCursors = function (test) { // http://www.mongodb.org/display/DOCS/Tailable+Cursors var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); db.open(function(err, db) { @@ -1977,7 +1977,7 @@ exports.shouldCloseDeadTailableCursors = function (test) { for(var end = insertId+1; insertId < end+80; insertId++) { docs.push({id:insertId}) } - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { test.equal(null, err); cb && cb(); }) @@ -2025,12 +2025,12 @@ exports.shouldCloseDeadTailableCursors = function (test) { exports.shouldAwaitData = function (test) { // http://www.mongodb.org/display/DOCS/Tailable+Cursors var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 2, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 2, ssl:useSSL}), {w:0, native_parser: native_parser}); db.open(function(err, db) { var options = { capped: true, size: 8}; db.createCollection('should_await_data', options, function(err, collection) { - collection.insert({a:1}, {safe:true}, function(err, result) { + collection.insert({a:1}, {w:1}, function(err, result) { // Create cursor with awaitdata, and timeout after the period specified collection.find({}, {tailable:true, awaitdata:true, numberOfRetries:1}).each(function(err, result) { if(err != null) { @@ -2071,10 +2071,10 @@ exports.shouldCorrectExecuteExplainHonoringLimit = function (test) { // Insert all the docs var collection = client.collection('shouldCorrectExecuteExplainHonoringLimit'); - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); - collection.ensureIndex({_keywords:1}, {safe:true}, function(err, result) { + collection.ensureIndex({_keywords:1}, {w:1}, function(err, result) { test.equal(null, err); // collection.find({_keywords:'red'},{}).limit(10).explain(function(err, result) { @@ -2097,7 +2097,7 @@ exports.shouldCorrectExecuteExplainHonoringLimit = function (test) { */ exports.shouldCorrectlyPerformResumeOnCursorStreamWithNoDuplicates = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -2114,7 +2114,7 @@ exports.shouldCorrectlyPerformResumeOnCursorStreamWithNoDuplicates = function(te test.equal(null, err); // Insert documents into collection - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { // Peform a find to get a cursor var stream = collection.find().stream(); stream.pause(); diff --git a/test/cursorstream_test.js b/test/cursorstream_test.js index d1abb1523c..328b176d63 100644 --- a/test/cursorstream_test.js +++ b/test/cursorstream_test.js @@ -24,7 +24,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -60,7 +60,7 @@ exports.tearDown = function(callback) { */ exports.shouldStreamDocumentsUsingTheCursorStreamPauseFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -76,7 +76,7 @@ exports.shouldStreamDocumentsUsingTheCursorStreamPauseFunction = function(test) test.equal(null, err); // Insert documents into collection - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { // Peform a find to get a cursor var stream = collection.find().stream(); @@ -118,7 +118,7 @@ exports.shouldStreamDocumentsUsingTheCursorStreamPauseFunction = function(test) */ exports.shouldStreamDocumentsUsingTheCursorStreamResumeFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -134,7 +134,7 @@ exports.shouldStreamDocumentsUsingTheCursorStreamResumeFunction = function(test) test.equal(null, err); // Insert documents into collection - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { // Peform a find to get a cursor var stream = collection.find().stream(); @@ -179,7 +179,7 @@ exports.shouldStreamDocumentsUsingTheCursorStreamResumeFunction = function(test) */ exports.shouldStreamDocumentsUsingTheCursorStreamDestroyFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -195,7 +195,7 @@ exports.shouldStreamDocumentsUsingTheCursorStreamDestroyFunction = function(test test.equal(null, err); // Insert documents into collection - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { // Peform a find to get a cursor var stream = collection.find().stream(); @@ -223,14 +223,14 @@ exports.shouldStreamDocumentsWithPauseAndResumeForFetching = function(test) { } var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 5, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 5, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { db.createCollection('test_streaming_function_with_limit_for_fetching', function(err, collection) { test.ok(collection instanceof Collection); - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { // Peform a find to get a cursor var stream = collection.find({}).stream(); var data = []; diff --git a/test/custom_pk_test.js b/test/custom_pk_test.js index 128349a09c..336c5c890c 100644 --- a/test/custom_pk_test.js +++ b/test/custom_pk_test.js @@ -23,7 +23,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -58,11 +58,11 @@ exports.shouldCreateRecordsWithCustomPKFactory = function(test) { return new ObjectID("aaaaaaaaaaaa"); } - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {ssl:useSSL}), {safe:false, 'pk':CustomPKFactory, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {ssl:useSSL}), {w:0, 'pk':CustomPKFactory, native_parser: (process.env['TEST_NATIVE'] != null)}); p_client.open(function(err, p_client) { p_client.dropDatabase(function(err, done) { p_client.createCollection('test_custom_key', function(err, collection) { - collection.insert({'a':1}, {safe:true}, function(err, doc) { + collection.insert({'a':1}, {w:1}, function(err, doc) { collection.find({'_id':new ObjectID("aaaaaaaaaaaa")}).toArray(function(err, items) { test.equal(1, items.length); diff --git a/test/db_test.js b/test/db_test.js index 96bee41105..5fff49df2a 100644 --- a/test/db_test.js +++ b/test/db_test.js @@ -26,7 +26,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -109,14 +109,14 @@ exports.shouldCorrectlyHandleIllegalDbNames = function(test) { * @ignore */ exports.shouldCorrectlyPerformAutomaticConnect = function(test) { - var automatic_connect_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null), retryMiliSeconds:50}); + var automatic_connect_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null), retryMiliSeconds:50}); automatic_connect_client.open(function(err, automatic_connect_client) { // Listener for closing event var closeListener = function(has_error) { // Let's insert a document automatic_connect_client.collection('test_object_id_generation.data2', function(err, collection) { // Insert another test document and collect using ObjectId - collection.insert({"name":"Patty", "age":34}, {safe:true}, function(err, ids) { + collection.insert({"name":"Patty", "age":34}, {w:1}, function(err, ids) { test.equal(1, ids.length); test.ok(ids[0]._id.toHexString().length == 24); @@ -145,7 +145,7 @@ exports.shouldCorrectlyPerformAutomaticConnect = function(test) { */ exports.shouldCorrectlyFailOnRetryDueToAppCloseOfDb = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -154,14 +154,14 @@ exports.shouldCorrectlyFailOnRetryDueToAppCloseOfDb = function(test) { db.collection('shouldCorrectlyFailOnRetryDueToAppCloseOfDb', function(err, collection) { // Insert a document - collection.insert({a:1}, {safe:true}, function(err, result) { + collection.insert({a:1}, {w:1}, function(err, result) { test.equal(null, err); // Force close the connection db.close(true, function(err, result) { // Attemp to insert should fail now with correct message 'db closed by application' - collection.insert({a:2}, {safe:true}, function(err, result) { + collection.insert({a:2}, {w:1}, function(err, result) { test.equal('db closed by application', err.message); test.done(); }); @@ -180,7 +180,7 @@ exports.shouldCorrectlyFailOnRetryDueToAppCloseOfDb = function(test) { */ exports.shouldCorrectlyExecuteEvalFunctions = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -257,17 +257,17 @@ exports.shouldCorrectlyExecuteEvalFunctions = function(test) { */ exports.shouldCorrectlyDefineSystemLevelFunctionAndExecuteFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { // Clean out the collection - db.collection("system.js").remove({}, {safe:true}, function(err, result) { + db.collection("system.js").remove({}, {w:1}, function(err, result) { test.equal(null, err); // Define a system level function - db.collection("system.js").insert({_id: "echo", value: new Code("function(x) { return x; }")}, {safe:true}, function(err, result) { + db.collection("system.js").insert({_id: "echo", value: new Code("function(x) { return x; }")}, {w:1}, function(err, result) { test.equal(null, err); db.eval("echo(5)", function(err, result) { @@ -287,14 +287,14 @@ exports.shouldCorrectlyDefineSystemLevelFunctionAndExecuteFunction = function(te */ exports.shouldCorrectlyDereferenceDbRef = function(test) { client.createCollection('test_deref', function(err, collection) { - collection.insert({'a':1}, {safe:true}, function(err, ids) { - collection.remove({}, {safe:true}, function(err, result) { + collection.insert({'a':1}, {w:1}, function(err, ids) { + collection.remove({}, {w:1}, function(err, result) { collection.count(function(err, count) { test.equal(0, count); // Execute deref a db reference client.dereference(new DBRef("test_deref", new ObjectID()), function(err, result) { - collection.insert({'x':'hello'}, {safe:true}, function(err, ids) { + collection.insert({'x':'hello'}, {w:1}, function(err, ids) { collection.findOne(function(err, document) { test.equal('hello', document.x); @@ -304,12 +304,12 @@ exports.shouldCorrectlyDereferenceDbRef = function(test) { client.dereference(new DBRef("test_deref", 4), function(err, result) { var obj = {'_id':4}; - collection.insert(obj, {safe:true}, function(err, ids) { + collection.insert(obj, {w:1}, function(err, ids) { client.dereference(new DBRef("test_deref", 4), function(err, document) { test.equal(obj['_id'], document._id); - collection.remove({}, {safe:true}, function(err, result) { - collection.insert({'x':'hello'}, {safe:true}, function(err, ids) { + collection.remove({}, {w:1}, function(err, result) { + collection.insert({'x':'hello'}, {w:1}, function(err, ids) { client.dereference(new DBRef("test_deref", null), function(err, result) { test.equal(null, result); // Let's close the db @@ -339,7 +339,7 @@ exports.shouldCorrectlyDereferenceDbRef = function(test) { */ exports.shouldCorrectlyRenameCollection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -396,7 +396,7 @@ exports.shouldCorrectlyRenameCollection = function(test) { } // Insert a couple of documents - collection1.insert([{'x':1}, {'x':2}], {safe:true}, function(err, docs) { + collection1.insert([{'x':1}, {'x':2}], {w:1}, function(err, docs) { // Attemp to rename the first collection to the second one, this will fail collection1.rename('test_rename_collection2', function(err, collection) { @@ -431,7 +431,7 @@ exports.shouldCorrectlyRenameCollection = function(test) { */ exports.shouldCorrectlyOpenASimpleDbSingleServerConnection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -451,7 +451,7 @@ exports.shouldCorrectlyOpenASimpleDbSingleServerConnection = function(test) { */ exports.shouldCorrectlyOpenASimpleDbSingleServerConnection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -475,7 +475,7 @@ exports.shouldCorrectlyOpenASimpleDbSingleServerConnection = function(test) { */ exports.shouldCorrectlyRetrieveCollectionInfo = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -514,7 +514,7 @@ exports.shouldCorrectlyRetrieveCollectionInfo = function(test) { */ exports.shouldCorrectlyRetrieveCollectionInfo = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -549,7 +549,7 @@ exports.shouldCorrectlyRetrieveCollectionInfo = function(test) { */ exports.shouldCorrectlyAccessACollection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -563,14 +563,14 @@ exports.shouldCorrectlyAccessACollection = function(test) { test.equal(null, err); // Grab a collection with a callback in safe mode, ensuring it exists (should fail as it's not created) - db.collection('test_correctly_access_collections', {safe:true}, function(err, col3) { + db.collection('test_correctly_access_collections', {strict:true}, function(err, col3) { test.ok(err != null); // Create the collection db.createCollection('test_correctly_access_collections', function(err, result) { // Retry to get the collection, should work as it's now created - db.collection('test_correctly_access_collections', {safe:true}, function(err, col3) { + db.collection('test_correctly_access_collections', {strict:true}, function(err, col3) { test.equal(null, err); db.close(); @@ -591,7 +591,7 @@ exports.shouldCorrectlyAccessACollection = function(test) { */ exports.shouldCorrectlyRetrieveAllCollections = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -616,7 +616,7 @@ exports.shouldCorrectlyRetrieveAllCollections = function(test) { * @ignore */ exports.shouldCorrectlyHandleFailedConnection = function(test) { - var fs_client = new Db(MONGODB, new Server("127.0.0.1", 25117, {auto_reconnect: false, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var fs_client = new Db(MONGODB, new Server("127.0.0.1", 25117, {auto_reconnect: false, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); fs_client.open(function(err, fs_client) { test.ok(err != null) test.done(); @@ -669,7 +669,7 @@ exports.shouldCorrectlyResaveDBRef = function(test) { */ exports.shouldCorrectlyDereferenceDbRefExamples = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -682,7 +682,7 @@ exports.shouldCorrectlyDereferenceDbRefExamples = function(test) { secondDb.createCollection('test_deref_examples', function(err, collection) { // Insert a document in the collection - collection.insert({'a':1}, {safe:true}, function(err, ids) { + collection.insert({'a':1}, {w:1}, function(err, ids) { // Let's build a db reference and resolve it var dbRef = new DBRef('test_deref_examples', ids[0]._id, 'integration_tests_2'); @@ -716,7 +716,7 @@ exports.shouldCorrectlyDereferenceDbRefExamples = function(test) { */ exports.shouldCorrectlyLogoutFromTheDatabase = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -751,7 +751,7 @@ exports.shouldCorrectlyLogoutFromTheDatabase = function(test) { */ exports.shouldCorrectlyAuthenticateAgainstTheDatabase = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -781,7 +781,7 @@ exports.shouldCorrectlyAuthenticateAgainstTheDatabase = function(test) { */ exports.shouldCorrectlyAuthenticateAgainstTheDatabase = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -806,7 +806,7 @@ exports.shouldCorrectlyAuthenticateAgainstTheDatabase = function(test) { */ exports.shouldCorrectlyAddAndRemoveUser = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -850,18 +850,18 @@ exports.shouldCorrectlyAddAndRemoveUser = function(test) { */ exports.shouldCorrectlyCreateACollection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { test.equal(null, err); // Create a capped collection with a maximum of 1000 documents - db.createCollection("a_simple_collection", {capped:true, size:10000, max:1000, safe:true}, function(err, collection) { + db.createCollection("a_simple_collection", {capped:true, size:10000, max:1000, w:1}, function(err, collection) { test.equal(null, err); // Insert a document in the capped collection - collection.insert({a:1}, {safe:true}, function(err, result) { + collection.insert({a:1}, {w:1}, function(err, result) { test.equal(null, err); db.close(); @@ -880,7 +880,7 @@ exports.shouldCorrectlyCreateACollection = function(test) { */ exports.shouldCorrectlyExecuteACommandAgainstTheServer = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -891,11 +891,11 @@ exports.shouldCorrectlyExecuteACommandAgainstTheServer = function(test) { test.equal(null, err); // Create a capped collection with a maximum of 1000 documents - db.createCollection("a_simple_create_drop_collection", {capped:true, size:10000, max:1000, safe:true}, function(err, collection) { + db.createCollection("a_simple_create_drop_collection", {capped:true, size:10000, max:1000, w:1}, function(err, collection) { test.equal(null, err); // Insert a document in the capped collection - collection.insert({a:1}, {safe:true}, function(err, result) { + collection.insert({a:1}, {w:1}, function(err, result) { test.equal(null, err); // Drop the collection from this world @@ -925,7 +925,7 @@ exports.shouldCorrectlyExecuteACommandAgainstTheServer = function(test) { */ exports.shouldCorrectlyCreateDropAndVerifyThatCollectionIsGone = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -950,18 +950,18 @@ exports.shouldCorrectlyCreateDropAndVerifyThatCollectionIsGone = function(test) */ exports.shouldCorrectlyRenameACollection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { test.equal(null, err); // Create a collection - db.createCollection("simple_rename_collection", {safe:true}, function(err, collection) { + db.createCollection("simple_rename_collection", {w:1}, function(err, collection) { test.equal(null, err); // Insert a document in the collection - collection.insert({a:1}, {safe:true}, function(err, result) { + collection.insert({a:1}, {w:1}, function(err, result) { test.equal(null, err); // Rename the collection @@ -1000,14 +1000,14 @@ exports.shouldCorrectlyRenameACollection = function(test) { */ exports.shouldCorrectlyUseLastError = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { test.equal(null, err); // Create a collection - db.createCollection("simple_rename_collection", {safe:true}, function(err, collection) { + db.createCollection("simple_rename_collection", {w:1}, function(err, collection) { test.equal(null, err); // Insert a document in the collection @@ -1044,18 +1044,18 @@ exports.shouldCorrectlyUseLastError = function(test) { */ exports.shouldCorrectlyUsePreviousError = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { test.equal(null, err); // Create a collection - db.createCollection("simple_previous_error_coll", {safe:true}, function(err, collection) { + db.createCollection("simple_previous_error_coll", {w:1}, function(err, collection) { test.equal(null, err); // Force a unique index - collection.ensureIndex({a:1}, {unique:true, safe:true}, function(err, result) { + collection.ensureIndex({a:1}, {unique:true, w:1}, function(err, result) { test.equal(null, err); // Force some errors @@ -1088,18 +1088,18 @@ exports.shouldCorrectlyUsePreviousError = function(test) { */ exports.shouldCorrectlyUseResetErrorHistory = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { test.equal(null, err); // Create a collection - db.createCollection("simple_reset_error_history_coll", {safe:true}, function(err, collection) { + db.createCollection("simple_reset_error_history_coll", {w:1}, function(err, collection) { test.equal(null, err); // Force a unique index - collection.ensureIndex({a:1}, {unique:true, safe:true}, function(err, result) { + collection.ensureIndex({a:1}, {unique:true, w:1}, function(err, result) { test.equal(null, err); // Force some errors @@ -1134,7 +1134,7 @@ exports.shouldCorrectlyUseResetErrorHistory = function(test) { */ exports.shouldCreateComplexIndexOnTwoFields = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1145,12 +1145,12 @@ exports.shouldCreateComplexIndexOnTwoFields = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field db.createIndex('more_complex_index_test', {a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Show that duplicate records got dropped collection.find({}).toArray(function(err, items) { @@ -1181,7 +1181,7 @@ exports.shouldCreateComplexIndexOnTwoFields = function(test) { */ exports.shouldCreateComplexEnsureIndex = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1192,12 +1192,12 @@ exports.shouldCreateComplexEnsureIndex = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field db.ensureIndex('more_complex_ensure_index_test', {a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Show that duplicate records got dropped collection.find({}).toArray(function(err, items) { @@ -1228,7 +1228,7 @@ exports.shouldCreateComplexEnsureIndex = function(test) { */ exports.shouldCorrectlyReturnCursorInformation = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1244,7 +1244,7 @@ exports.shouldCorrectlyReturnCursorInformation = function(test) { } // Insert a bunch of documents for the index - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); // Let's set a cursor @@ -1273,7 +1273,7 @@ exports.shouldCorrectlyReturnCursorInformation = function(test) { */ exports.shouldCorrectlyCreateAndDropIndex = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1284,12 +1284,12 @@ exports.shouldCorrectlyCreateAndDropIndex = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field collection.ensureIndex({a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Drop the index db.dropIndex("create_and_drop_an_index", "a_1_b_1", function(err, result) { @@ -1318,7 +1318,7 @@ exports.shouldCorrectlyCreateAndDropIndex = function(test) { */ exports.shouldCorrectlyForceReindexOnCollection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1329,12 +1329,12 @@ exports.shouldCorrectlyForceReindexOnCollection = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field collection.ensureIndex({a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Force a reindex of the collection db.reIndex('create_and_drop_all_indexes', function(err, result) { @@ -1364,7 +1364,7 @@ exports.shouldCorrectlyForceReindexOnCollection = function(test) { */ exports.shouldCorrectlyShowTheResultsFromIndexInformation = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1375,12 +1375,12 @@ exports.shouldCorrectlyShowTheResultsFromIndexInformation = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field collection.ensureIndex({a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Fetch basic indexInformation for collection db.indexInformation('more_index_information_test', function(err, indexInformation) { @@ -1410,7 +1410,7 @@ exports.shouldCorrectlyShowTheResultsFromIndexInformation = function(test) { */ exports.shouldCorrectlyShowTheResultsFromIndexInformation = function(test) { var db = new Db('integration_tests_to_drop', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1421,7 +1421,7 @@ exports.shouldCorrectlyShowTheResultsFromIndexInformation = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) { test.equal(null, err); // Let's drop the database @@ -1460,7 +1460,7 @@ exports.shouldCorrectlyShowTheResultsFromIndexInformation = function(test) { */ exports.shouldCorrectlyGetErrorDroppingNonExistingDb = function(test) { var db = new Db('integration_tests_to_drop_2', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1481,7 +1481,7 @@ exports.shouldCorrectlyGetErrorDroppingNonExistingDb = function(test) { */ exports.shouldCorrectlyThrowWhenTryingToReOpenConnection = function(test) { var db = new Db('integration_tests_to_drop_2', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1501,7 +1501,7 @@ exports.shouldCorrectlyThrowWhenTryingToReOpenConnection = function(test) { */ exports.shouldCorrectlyReconnectWhenError = function(test) { var db = new Db('integration_tests_to_drop_2', new Server("127.0.0.1", 27088, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, _db) { test.ok(err != null); @@ -1523,7 +1523,7 @@ exports.shouldCorrectlyReconnectWhenError = function(test) { */ exports.shouldCorrectlyRetrieveDbStats = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { diff --git a/test/domain_socket_test.js b/test/domain_socket_test.js index 66f97c7ad7..87e129aedd 100644 --- a/test/domain_socket_test.js +++ b/test/domain_socket_test.js @@ -22,7 +22,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -56,10 +56,10 @@ exports.tearDown = function(callback) { */ exports['Should correctly connect to server using domain socket'] = function(test) { - var db = new Db(MONGODB, new Server("/tmp/mongodb-27017.sock", {safe:false, auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server("/tmp/mongodb-27017.sock", {w:0, auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, db) { - db.collection("domainSocketCollection").insert({a:1}, {safe:true}, function(err, item) { + db.collection("domainSocketCollection").insert({a:1}, {w:1}, function(err, item) { test.equal(null, err); db.collection("domainSocketCollection").find({a:1}).toArray(function(err, items) { diff --git a/test/error_test.js b/test/error_test.js index 028043974e..1a9e85b4e1 100644 --- a/test/error_test.js +++ b/test/error_test.js @@ -22,7 +22,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -52,7 +52,7 @@ exports.tearDown = function(callback) { // Test the error reporting functionality exports.shouldCorrectlyRetrieveErrorMessagesFromServer = function(test) { // Just run with one connection in the pool - var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, poolSize:1, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, poolSize:1, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Open the db error_client.open(function(err, error_client) { error_client.resetErrorHistory(function() { @@ -116,7 +116,7 @@ exports.shouldCorrectlyRetrieveErrorMessagesFromServer = function(test) { // Test the last status functionality of the driver exports.shouldCorrectlyExecuteLastStatus = function(test) { // Just run with one connection in the pool - var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, poolSize:1, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, poolSize:1, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Open the db error_client.open(function(err, client) { client.createCollection('test_last_status', function(err, collection) { @@ -174,7 +174,7 @@ exports.shouldCorrectlyExecuteLastStatus = function(test) { exports.shouldFailInsertDueToUniqueIndex = function(test) { client.createCollection('test_failing_insert_due_to_unique_index', function(err, r) { client.collection('test_failing_insert_due_to_unique_index', function(err, collection) { - collection.ensureIndex([['a', 1 ]], {unique:true, safe:true}, function(err, indexName) { + collection.ensureIndex([['a', 1 ]], {unique:true, w:1}, function(err, indexName) { collection.insert({a:2}, {safe: true}, function(err, r) { test.ok(err == null); collection.insert({a:2}, {safe: true}, function(err, r) { @@ -189,15 +189,15 @@ exports.shouldFailInsertDueToUniqueIndex = function(test) { // Test the error reporting functionality exports.shouldFailInsertDueToUniqueIndexStrict = function(test) { - var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); error_client.open(function(err, error_client) { error_client.dropCollection('test_failing_insert_due_to_unique_index_strict', function(err, r) { error_client.createCollection('test_failing_insert_due_to_unique_index_strict', function(err, r) { error_client.collection('test_failing_insert_due_to_unique_index_strict', function(err, collection) { - collection.ensureIndex([['a', 1 ]], {unique:true, safe:true}, function(err, indexName) { - collection.insert({a:2}, {safe:true}, function(err, r) { + collection.ensureIndex([['a', 1 ]], {unique:true, w:1}, function(err, indexName) { + collection.insert({a:2}, {w:1}, function(err, r) { test.ok(err == null); - collection.insert({a:2}, {safe:true}, function(err, r) { + collection.insert({a:2}, {w:1}, function(err, r) { test.ok(err != null); error_client.close(); test.done(); @@ -211,7 +211,7 @@ exports.shouldFailInsertDueToUniqueIndexStrict = function(test) { } exports['safe mode should pass the disconnected error to the callback'] = function (test) { - var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var error_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var name = 'test_safe_mode_when_disconnected'; error_client.open(function(err, error_client) { test.ok(err == null); @@ -262,7 +262,7 @@ exports.shouldHandleAssertionError = function(test) { collection.findOne(query, function(err, docs) { test.ok(err instanceof Error); - collection.ensureIndex([['a', '2d' ]], {unique:true, safe:true}, function(err, indexName) { + collection.ensureIndex([['a', '2d' ]], {unique:true, w:1}, function(err, indexName) { test.ok(err == null); collection.findOne(query, function(err, doc) { @@ -293,7 +293,7 @@ exports.shouldHandleAssertionError = function(test) { exports['mixing included and excluded fields should return an error object with message'] = function (test) { client.createCollection('test_error_object_should_include_message', function(err, c) { test.equal(err, null); - c.insert({a:2, b: 5}, {safe:true}, function(err, r) { + c.insert({a:2, b: 5}, {w:1}, function(err, r) { test.equal(err, null); c.findOne({a:2}, {fields: {a:1, b:0}}, function(err) { test.ok(err); diff --git a/test/exception_handling_test.js b/test/exception_handling_test.js index a61684c52d..2c72b1c450 100644 --- a/test/exception_handling_test.js +++ b/test/exception_handling_test.js @@ -22,7 +22,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db diff --git a/test/find_test.js b/test/find_test.js index 088d22966d..450ecd63ec 100644 --- a/test/find_test.js +++ b/test/find_test.js @@ -30,7 +30,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -68,7 +68,7 @@ exports.shouldCorrectlyPerformSimpleFind = function(test) { var doc2 = null; // Insert some test documents - collection.insert([{a:2}, {b:3}], {safe:true}, function(err, docs) { + collection.insert([{a:2}, {b:3}], {w:1}, function(err, docs) { doc1 = docs[0]; doc2 = docs[1] @@ -104,7 +104,7 @@ exports.shouldCorrectlyPeformSimpleChainedFind = function(test) { var doc2 = null; // Insert some test documents - collection.insert([{a:2}, {b:3}], {safe:true}, function(err, docs) { + collection.insert([{a:2}, {b:3}], {w:1}, function(err, docs) { doc1 = docs[0]; doc2 = docs[1] @@ -139,7 +139,7 @@ exports.shouldCorrectlyPeformAdvancedFinds = function(test) { var doc1 = null, doc2 = null, doc3 = null; // Insert some test documents - collection.insert([{a:1}, {a:2}, {b:3}], {safe:true}, function(err, docs) { + collection.insert([{a:1}, {a:2}, {b:3}], {w:1}, function(err, docs) { var doc1 = docs[0], doc2 = docs[1], doc3 = docs[2]; // Locate by less than @@ -227,7 +227,7 @@ exports.shouldCorrectlyPerformFindWithSort = function(test) { {a:2, b:1}, {a:3, b:2}, {a:4, b:1} - ], {safe:true}, function(err, docs) { + ], {w:1}, function(err, docs) { doc1 = docs[0]; doc2 = docs[1]; doc3 = docs[2]; @@ -327,7 +327,7 @@ exports.shouldCorrectlyPerformFindWithLimit = function(test) { {b:2}, {c:3}, {d:4} - ], {safe:true}, function(err, docs) { + ], {w:1}, function(err, docs) { doc1 = docs[0]; doc2 = docs[1]; doc3 = docs[2]; @@ -373,7 +373,7 @@ exports.shouldCorrectlyFindWithNonQuotedValues = function(test) { client.collection('test_find_non_quoted_values', function(err, collection) { // insert test document collection.insert([{ a: 19, b: 'teststring', c: 59920303 }, - { a: "19", b: 'teststring', c: 3984929 }], {safe:true} , function(err, r) { + { a: "19", b: 'teststring', c: 3984929 }], {w:1} , function(err, r) { collection.find({ a: 19 }).toArray(function(err, documents) { test.equal(1, documents.length); @@ -393,7 +393,7 @@ exports.shouldCorrectlyFindEmbeddedDocument = function(test) { client.collection('test_find_embedded_document', function(err, collection) { // insert test document collection.insert([{ a: { id: 10, value: 'foo' }, b: 'bar', c: { id: 20, value: 'foobar' }}, - { a: { id: 11, value: 'foo' }, b: 'bar2', c: { id: 20, value: 'foobar' }}], {safe:true}, function(err, r) { + { a: { id: 11, value: 'foo' }, b: 'bar2', c: { id: 20, value: 'foobar' }}], {w:1}, function(err, r) { // test using integer value collection.find({ 'a.id': 10 }).toArray(function(err, documents) { @@ -436,7 +436,7 @@ exports.shouldCorrectlyFindNoRecords = function(test) { exports.shouldCorrectlyPerformFindByWhere = function(test) { client.createCollection('test_where', function(err, collection) { test.ok(collection instanceof Collection); - collection.insert([{'a':1}, {'a':2}, {'a':3}], {safe:true}, function(err, ids) { + collection.insert([{'a':1}, {'a':2}, {'a':3}], {w:1}, function(err, ids) { collection.count(function(err, count) { test.equal(3, count); @@ -461,8 +461,8 @@ exports.shouldCorrectlyPerformFindByWhere = function(test) { */ exports.shouldCorrectlyPerformFindsWithHintTurnedOn = function(test) { client.createCollection('test_hint', function(err, collection) { - collection.insert({'a':1}, {safe:true}, function(err, ids) { - client.createIndex(collection.collectionName, "a", {safe:true}, function(err, indexName) { + collection.insert({'a':1}, {w:1}, function(err, ids) { + client.createIndex(collection.collectionName, "a", {w:1}, function(err, indexName) { collection.find({'a':1}, {'hint':'a'}).toArray(function(err, items) { test.equal(1, items.length); }); @@ -511,7 +511,7 @@ exports.shouldCorrectlyPerformFindsWithHintTurnedOn = function(test) { */ exports.shouldCorrectlyPerformFindByObjectID = function(test) { client.createCollection('test_find_by_oid', function(err, collection) { - collection.save({'hello':'mike'}, {safe:true}, function(err, docs) { + collection.save({'hello':'mike'}, {w:1}, function(err, docs) { test.ok(docs._id instanceof ObjectID || Object.prototype.toString.call(docs._id) === '[object ObjectID]'); collection.findOne({'_id':docs._id}, function(err, doc) { @@ -542,8 +542,8 @@ exports.shouldCorrectlyReturnDocumentWithOriginalStructure= function(test) { , _id: new ObjectID }; - collection.insert(doc, {safe:true}, function(err, docs) { - collection.findOne({'_id':doc._id}, {safe:true,fields: undefined}, function(err, doc) { + collection.insert(doc, {w:1}, function(err, docs) { + collection.findOne({'_id':doc._id}, {w:1,fields: undefined}, function(err, doc) { if (err) console.error('error', err); test.equal(2, doc.comments.length); test.equal('number 1', doc.comments[0].title); @@ -559,10 +559,10 @@ exports.shouldCorrectlyReturnDocumentWithOriginalStructure= function(test) { * @ignore */ exports.shouldCorrectlyRetrieveSingleRecord = function(test) { - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); p_client.open(function(err, p_client) { client.createCollection('test_should_correctly_retrieve_one_record', function(err, collection) { - collection.insert({'a':0}, {safe:true}, function(err, r) { + collection.insert({'a':0}, {w:1}, function(err, r) { p_client.collection('test_should_correctly_retrieve_one_record', function(err, usercollection) { usercollection.findOne({'a': 0}, function(err, result) { p_client.close(); @@ -601,7 +601,7 @@ exports.shouldCorrectlyPerformFindWithOptions = function(test) { // Insert some test documents while(docCount--) docs.push({a:docCount, b:docCount}); - collection.insert(docs, {safe:true}, function(err,retDocs) { + collection.insert(docs, {w:1}, function(err,retDocs) { docs = retDocs; collection.find({},{ 'a' : 1},{ limit : 3, sort : [['a',-1]] }).toArray(function(err,documents){ @@ -633,21 +633,21 @@ exports.shouldCorrectlyPerformFindWithOptions = function(test) { exports.shouldCorrectlyFindAndModifyDocument = function(test) { client.createCollection('test_find_and_modify_a_document', function(err, collection) { // Test return new document on change - collection.insert({'a':1, 'b':2}, {safe:true}, function(err, doc) { + collection.insert({'a':1, 'b':2}, {w:1}, function(err, doc) { // Let's modify the document in place collection.findAndModify({'a':1}, [['a', 1]], {'$set':{'b':3}}, {'new':true}, function(err, updated_doc) { test.equal(1, updated_doc.a); test.equal(3, updated_doc.b); // Test return old document on change - collection.insert({'a':2, 'b':2}, {safe:true}, function(err, doc) { + collection.insert({'a':2, 'b':2}, {w:1}, function(err, doc) { // Let's modify the document in place - collection.findAndModify({'a':2}, [['a', 1]], {'$set':{'b':3}}, {safe:true}, function(err, result, object) { + collection.findAndModify({'a':2}, [['a', 1]], {'$set':{'b':3}}, {w:1}, function(err, result, object) { test.equal(2, result.a); test.equal(2, result.b); // Test remove object on change - collection.insert({'a':3, 'b':2}, {safe:true}, function(err, doc) { + collection.insert({'a':3, 'b':2}, {w:1}, function(err, doc) { // Let's modify the document in place collection.findAndModify({'a':3}, [], {'$set':{'b':3}}, {'new': true, remove: true}, function(err, updated_doc) { test.equal(3, updated_doc.a); @@ -659,7 +659,7 @@ exports.shouldCorrectlyFindAndModifyDocument = function(test) { test.equal(3, updated_doc.b); // Test selecting a subset of fields - collection.insert({a: 100, b: 101}, {safe:true}, function (err, ids) { + collection.insert({a: 100, b: 101}, {w:1}, function (err, ids) { collection.findAndModify({'a': 100}, [], {'$set': {'b': 5}}, {'new': true, fields: {b: 1}}, function (err, updated_doc) { test.equal(2, Object.keys(updated_doc).length); test.equal(ids[0]['_id'].toHexString(), updated_doc._id.toHexString()); @@ -685,7 +685,7 @@ exports.shouldCorrectlyFindAndModifyDocument = function(test) { exports.shouldCorrectlyFindAndModifyDocumentAndReturnSelectedFieldsOnly = function(test) { client.createCollection('test_find_and_modify_a_document', function(err, collection) { // Test return new document on change - collection.insert({'a':1, 'b':2}, {safe:true}, function(err, doc) { + collection.insert({'a':1, 'b':2}, {w:1}, function(err, doc) { // Let's modify the document in place collection.findAndModify({'a':1}, [['a', 1]], {'$set':{'b':3}}, {'new':true, 'fields': {a:1}}, function(err, updated_doc) { test.equal(2, Object.keys(updated_doc).length); @@ -702,7 +702,7 @@ exports.shouldCorrectlyFindAndModifyDocumentAndReturnSelectedFieldsOnly = functi exports.shouldCorrectlyExecuteFindOneWithAnInSearchTag = function(test) { client.createCollection('shouldCorrectlyExecuteFindOneWithAnInSearchTag', function(err, collection) { // Test return new document on change - collection.insert({'tags':[]}, {safe:true}, function(err, docs) { + collection.insert({'tags':[]}, {w:1}, function(err, docs) { // Fetch the id var id = docs[0]._id @@ -715,7 +715,7 @@ exports.shouldCorrectlyExecuteFindOneWithAnInSearchTag = function(test) { test.ok(doc != null); // Perform atomic push operation - collection.update({_id:id}, {'$push':{comments:{title:'1'}}}, {safe:true}, self); + collection.update({_id:id}, {'$push':{comments:{title:'1'}}}, {w:1}, self); }) }, @@ -730,7 +730,7 @@ exports.shouldCorrectlyExecuteFindOneWithAnInSearchTag = function(test) { test.deepEqual(1, doc.comments.length); // Perform atomic push operation - collection.update({_id:id}, {'$push':{comments:{title:'2'}}}, {safe:true}, self); + collection.update({_id:id}, {'$push':{comments:{title:'2'}}}, {w:1}, self); }) }, @@ -745,7 +745,7 @@ exports.shouldCorrectlyExecuteFindOneWithAnInSearchTag = function(test) { test.deepEqual(2, doc.comments.length); // Perform atomic push operation - collection.update({_id:id}, {'$push':{comments:{title:'3'}}}, {safe:true}, self); + collection.update({_id:id}, {'$push':{comments:{title:'3'}}}, {w:1}, self); }) }, @@ -759,7 +759,7 @@ exports.shouldCorrectlyExecuteFindOneWithAnInSearchTag = function(test) { test.ok(doc != null); test.deepEqual(3, doc.comments.length); // Perform atomic push operation - collection.update({_id:id}, {'$pushAll':{comments:[{title:'4'}, {title:'5'}]}}, {safe:true}, self); + collection.update({_id:id}, {'$pushAll':{comments:[{title:'4'}, {title:'5'}]}}, {w:1}, self); }) }, @@ -788,11 +788,11 @@ exports['ShouldCorrectlyLocatePostAndIncValues'] = function(test) { // Test return new document on change collection.insert({title:'Tobi', author:'Brian', - newTitle:'Woot', meta:{visitors:0}}, {safe:true}, function(err, docs) { + newTitle:'Woot', meta:{visitors:0}}, {w:1}, function(err, docs) { // Fetch the id var id = docs[0]._id - collection.update({_id:id}, {$inc:{ 'meta.visitors': 1 }}, {safe:true}, function(err, result) { + collection.update({_id:id}, {$inc:{ 'meta.visitors': 1 }}, {w:1}, function(err, result) { test.equal(1, result); test.equal(null, err); @@ -811,9 +811,9 @@ exports['ShouldCorrectlyLocatePostAndIncValues'] = function(test) { */ exports['Should Correctly Handle FindAndModify Duplicate Key Error'] = function(test) { client.createCollection('FindAndModifyDuplicateKeyError', function(err, collection) { - collection.ensureIndex(['name', 1], {unique:true, safe:true}, function(err, index) { + collection.ensureIndex(['name', 1], {unique:true, w:1}, function(err, index) { // Test return new document on change - collection.insert([{name:'test1'}, {name:'test2'}], {safe:true}, function(err, doc) { + collection.insert([{name:'test1'}, {name:'test2'}], {w:1}, function(err, doc) { // Let's modify the document in place collection.findAndModify({name: 'test1'}, [], {$set: {name: 'test2'}}, {}, function(err, updated_doc) { test.equal(null, updated_doc); @@ -844,7 +844,7 @@ exports['Should correctly return null when attempting to modify a non-existing d */ exports['Should correctly handle chained skip and limit on find with toArray'] = function(test) { client.createCollection('skipAndLimitOnFindWithToArray', function(err, collection) { - collection.insert([{a:1}, {b:2}, {c:3}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2}, {c:3}], {w:1}, function(err, result) { collection.find().skip(1).limit(-1).toArray(function(err, items) { test.equal(null, err); @@ -861,7 +861,7 @@ exports['Should correctly handle chained skip and limit on find with toArray'] = */ exports['Should correctly handle chained skip and negative limit on find with toArray'] = function(test) { client.createCollection('skipAndNegativeLimitOnFindWithToArray', function(err, collection) { - collection.insert([{a:1}, {b:2}, {c:3}, {d:4}, {e:5}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2}, {c:3}, {d:4}, {e:5}], {w:1}, function(err, result) { collection.find().skip(1).limit(-3).toArray(function(err, items) { test.equal(null, err); @@ -899,11 +899,11 @@ exports['Should correctly pass timeout options to cursor'] = function(test) { * @ignore */ exports.shouldCorrectlyFindAndModifyDocumentWithDBStrict = function(test) { - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {safe:true, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {w:1, native_parser: (process.env['TEST_NATIVE'] != null)}); p_client.open(function(err, p_client) { p_client.createCollection('shouldCorrectlyFindAndModifyDocumentWithDBStrict', function(err, collection) { // Test return old document on change - collection.insert({'a':2, 'b':2}, {safe:true}, function(err, doc) { + collection.insert({'a':2, 'b':2}, {w:1}, function(err, doc) { // Let's modify the document in place collection.findAndModify({'a':2}, [['a', 1]], {'$set':{'b':3}}, {new:true}, function(err, result) { test.equal(2, result.a) @@ -923,12 +923,12 @@ exports.shouldCorrectlyFindAndModifyDocumentWithDBStrict = function(test) { exports.shouldCorrectlyFindAndModifyDocumentThatFailsInFirstStep = function(test) { client.createCollection('shouldCorrectlyFindAndModifyDocumentThatFailsInFirstStep', function(err, collection) { // Set up an index to force duplicate index erro - collection.ensureIndex([['failIndex', 1]], {unique:true, safe:true}, function(err, index) { + collection.ensureIndex([['failIndex', 1]], {unique:true, w:1}, function(err, index) { // Setup a new document - collection.insert({'a':2, 'b':2, 'failIndex':2}, {safe:true}, function(err, doc) { + collection.insert({'a':2, 'b':2, 'failIndex':2}, {w:1}, function(err, doc) { // Let's attempt to upsert with a duplicate key error - collection.findAndModify({'c':2}, [['a', 1]], {'a':10, 'b':10, 'failIndex':2}, {safe:true, upsert:true}, function(err, result) { + collection.findAndModify({'c':2}, [['a', 1]], {'a':10, 'b':10, 'failIndex':2}, {w:1, upsert:true}, function(err, result) { test.equal(null, result); test.ok(err.errmsg.match("duplicate key error index")); test.done(); @@ -943,7 +943,7 @@ exports.shouldCorrectlyFindAndModifyDocumentThatFailsInFirstStep = function(test * @ignore */ exports.shouldCorrectlyFindAndModifyDocumentThatFailsInSecondStepWithNoMatchingDocuments = function(test) { - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {safe:true, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {w:1, native_parser: (process.env['TEST_NATIVE'] != null)}); p_client.open(function(err, p_client) { p_client.createCollection('shouldCorrectlyFindAndModifyDocumentThatFailsInSecondStepWithNoMatchingDocuments', function(err, collection) { // Test return old document on change @@ -969,7 +969,7 @@ exports['Should correctly return new modified document'] = function(test) { var id = new ObjectID(); var doc = {_id:id, a:1, b:1, c:{a:1, b:1}}; - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.ok(err == null); // Find and modify returning the new object @@ -1019,7 +1019,7 @@ exports['Should correctly return record with 64-bit id'] = function(test) { var lowerDoc = {_id:_lowerId, id: lowerId}; var higherDoc = {_id:_higherId, id: higherId}; - collection.insert([lowerDoc, higherDoc], {safe:true}, function(err, result) { + collection.insert([lowerDoc, higherDoc], {w:1}, function(err, result) { test.ok(err == null); // Select record with id of 133118461172916225 using $gt directive @@ -1037,12 +1037,12 @@ exports['Should correctly return record with 64-bit id'] = function(test) { * @ignore */ exports['Should Correctly find a Document using findOne excluding _id field'] = function(test) { - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {safe:true, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {w:1, native_parser: (process.env['TEST_NATIVE'] != null)}); p_client.open(function(err, p_client) { client.createCollection('Should_Correctly_find_a_Document_using_findOne_excluding__id_field', function(err, collection) { var doc = {_id : new ObjectID(), a:1, c:2} // insert doc - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { // Get one document, excluding the _id field collection.findOne({a:1}, {fields:{'_id': 0}}, function(err, item) { test.equal(null, item._id); @@ -1070,7 +1070,7 @@ exports['Should correctly execute find and findOne queries in the same way'] = f client.createCollection('Should_correctly_execute_find_and_findOne_queries_in_the_same_way', function(err, collection) { var doc = {_id : new ObjectID(), a:1, c:2, comments:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}; // insert doc - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { collection.find({_id: doc._id}, {comments: {$slice: -5}}).toArray(function(err, docs) { test.equal(5, docs[0].comments.length) @@ -1091,7 +1091,7 @@ exports['Should correctly execute find and findOne queries with selector set to client.createCollection('Should_correctly_execute_find_and_findOne_queries_in_the_same_way', function(err, collection) { var doc = {_id : new ObjectID(), a:1, c:2, comments:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}; // insert doc - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { collection.find(null, {comments: {$slice: -5}}).toArray(function(err, docs) { test.equal(5, docs[0].comments.length) @@ -1141,7 +1141,7 @@ exports.shouldCorrectlyExecuteFindAndModifyShouldGenerateCorrectBSON = function( } client.createCollection('shouldCorrectlyExecuteFindAndModify', function(err, collection) { - collection.insert(wrapingObject, {safe:true}, function(err, doc) { + collection.insert(wrapingObject, {w:1}, function(err, doc) { test.equal(null, err); collection.findOne({_id:doc[0]._id, 'funds.remaining': {$gte: 3.0}, 'transactions.id': {$ne: transaction.transactionId}}, function(err, item) { @@ -1159,13 +1159,13 @@ exports.shouldCorrectlyExecuteFindAndModifyShouldGenerateCorrectBSON = function( * @ignore */ exports.shouldCorrectlyExecuteMultipleFindsInParallel = function(test) { - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize:10, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize:10, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); p_client.open(function(err, p_client) { p_client.createCollection('tasks', function(err, collection) { var numberOfOperations = 0; // Test return old document on change - collection.insert({'a':2, 'b':2}, {safe:true}, function(err, doc) { + collection.insert({'a':2, 'b':2}, {w:1}, function(err, doc) { collection.find({"user_id":"4e9fc8d55883d90100000003","lc_status":{"$ne":"deleted"},"owner_rating":{"$exists":false}}, {"skip":0,"limit":10,"sort":{"updated":-1}}).count(function(err, count) { numberOfOperations = numberOfOperations + 1; @@ -1200,7 +1200,7 @@ exports.shouldCorrectlyReturnErrorFromMongodbOnFindAndModifyForcedError = functi var doc = {_id: new ObjectID(), x:1}; // Insert original doc - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { collection.findAndModify(q, [], set, opts, function (err, res) { test.ok(err != null); test.done(); @@ -1213,7 +1213,7 @@ exports.shouldCorrectlyReturnErrorFromMongodbOnFindAndModifyForcedError = functi * @ignore */ exports.shouldCorrectlyExecuteFindAndModifyUnderConcurrentLoad = function(test) { - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize:10, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize:10, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var running = true; p_client.open(function(err, p_client) { @@ -1223,10 +1223,10 @@ exports.shouldCorrectlyExecuteFindAndModifyUnderConcurrentLoad = function(test) setTimeout(function() { var id = new ObjectID(); - collection.insert({_id:id, a:1}, {safe:true}, function(err, result) { + collection.insert({_id:id, a:1}, {w:1}, function(err, result) { test.equal(null, err); - collection.insert({_id:id, a:1}, {safe:true}, function(err, result) { + collection.insert({_id:id, a:1}, {w:1}, function(err, result) { running = false; test.done(); p_client.close(); @@ -1251,7 +1251,7 @@ exports.shouldCorrectlyExecuteFindAndModifyUnderConcurrentLoad = function(test) * @ignore */ exports.shouldCorrectlyIterateOverCollection = function(test) { - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize:1, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize:1, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var numberOfSteps = 0; // Open db connection @@ -1282,14 +1282,14 @@ exports.shouldCorrectlyIterateOverCollection = function(test) { * @ignore */ exports.shouldCorrectlyErrorOutFindAndModifyOnDuplicateRecord = function(test) { - var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {safe:true, native_parser: (process.env['TEST_NATIVE'] != null)}); + var p_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {w:1, native_parser: (process.env['TEST_NATIVE'] != null)}); p_client.open(function(err, p_client) { p_client.createCollection('shouldCorrectlyErrorOutFindAndModifyOnDuplicateRecord', function(err, collection) { // Test return old document on change - collection.insert([{'login':'user1'}, {'login':'user2'}], {safe:true}, function(err, docs) { + collection.insert([{'login':'user1'}, {'login':'user2'}], {w:1}, function(err, docs) { var id = docs[1]._id; // Set an index - collection.ensureIndex('login', {unique:true, safe:true}, function(err, result) { + collection.ensureIndex('login', {unique:true, w:1}, function(err, result) { // Attemp to modify document collection.findAndModify({_id: id}, [], { $set: {login: 'user1'} }, {}, function(err, user){ test.ok(err != null); @@ -1309,7 +1309,7 @@ exports.shouldCorrectlyErrorOutFindAndModifyOnDuplicateRecord = function(test) { */ exports.shouldPerformSimpleFindInArray = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1322,7 +1322,7 @@ exports.shouldPerformSimpleFindInArray = function(test) { for(var i = 0; i < 100; i++) docs.push({a:i}); // Insert some test documentations - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); // Find all the variables in a specific array @@ -1354,7 +1354,7 @@ exports.shouldPerformSimpleFindInArray = function(test) { */ exports.shouldPerformSimpleFindAndModifyOperations = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1364,7 +1364,7 @@ exports.shouldPerformSimpleFindAndModifyOperations = function(test) { test.equal(null, err); // Insert some test documentations - collection.insert([{a:1}, {b:1}, {c:1}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:1}, {c:1}], {w:1}, function(err, result) { test.equal(null, err); // Simple findAndModify command returning the new document @@ -1386,7 +1386,7 @@ exports.shouldPerformSimpleFindAndModifyOperations = function(test) { // Simple findAndModify command performing an upsert and returning the new document // executing the command safely collection.findAndModify({d:1}, [['b', 1]], - {d:1, f:1}, {new:true, upsert:true, safe:true}, function(err, doc) { + {d:1, f:1}, {new:true, upsert:true, w:1}, function(err, doc) { test.equal(null, err); test.equal(1, doc.d); test.equal(1, doc.f); @@ -1410,7 +1410,7 @@ exports.shouldPerformSimpleFindAndModifyOperations = function(test) { */ exports.shouldPerformSimpleFindAndModifyOperations = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1420,7 +1420,7 @@ exports.shouldPerformSimpleFindAndModifyOperations = function(test) { test.equal(null, err); // Insert some test documentations - collection.insert([{a:1}, {b:1}, {c:1}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:1}, {c:1}], {w:1}, function(err, result) { test.equal(null, err); // Simple findAndModify command returning the new document and @@ -1451,7 +1451,7 @@ exports.shouldPerformSimpleFindAndModifyOperations = function(test) { */ exports.shouldPeformASimpleQuery = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1461,7 +1461,7 @@ exports.shouldPeformASimpleQuery = function(test) { test.equal(null, err); // Insert a bunch of documents for the testing - collection.insert([{a:1}, {a:2}, {a:3}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {a:2}, {a:3}], {w:1}, function(err, result) { test.equal(null, err); // Peform a simple find and return all the documents @@ -1485,7 +1485,7 @@ exports.shouldPeformASimpleQuery = function(test) { */ exports.shouldPeformASimpleExplainQuery = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1495,7 +1495,7 @@ exports.shouldPeformASimpleExplainQuery = function(test) { test.equal(null, err); // Insert a bunch of documents for the testing - collection.insert([{a:1}, {a:2}, {a:3}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {a:2}, {a:3}], {w:1}, function(err, result) { test.equal(null, err); // Peform a simple find and return all the documents @@ -1519,7 +1519,7 @@ exports.shouldPeformASimpleExplainQuery = function(test) { */ exports.shouldPeformASimpleLimitSkipQuery = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1529,7 +1529,7 @@ exports.shouldPeformASimpleLimitSkipQuery = function(test) { test.equal(null, err); // Insert a bunch of documents for the testing - collection.insert([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {safe:true}, function(err, result) { + collection.insert([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}, function(err, result) { test.equal(null, err); // Peform a simple find and return all the documents @@ -1555,7 +1555,7 @@ exports.shouldPeformASimpleLimitSkipQuery = function(test) { */ exports.shouldPeformASimpleLimitSkipFindOneQuery = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1565,7 +1565,7 @@ exports.shouldPeformASimpleLimitSkipFindOneQuery = function(test) { test.equal(null, err); // Insert a bunch of documents for the testing - collection.insert([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {safe:true}, function(err, result) { + collection.insert([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}, function(err, result) { test.equal(null, err); // Peform a simple find and return all the documents @@ -1587,7 +1587,7 @@ exports.shouldPeformASimpleLimitSkipFindOneQuery = function(test) { */ exports.shouldPeformASimpleLimitSkipFindWithFields = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1597,7 +1597,7 @@ exports.shouldPeformASimpleLimitSkipFindWithFields = function(test) { test.equal(null, err); // Insert a bunch of documents for the testing - collection.insert([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {safe:true}, function(err, result) { + collection.insert([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}, function(err, result) { test.equal(null, err); // Peform a simple find and return all the documents @@ -1628,7 +1628,7 @@ exports.shouldPeformASimpleLimitSkipFindWithFields = function(test) { */ exports.shouldPeformASimpleLimitSkipFindWithFields2 = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1638,7 +1638,7 @@ exports.shouldPeformASimpleLimitSkipFindWithFields2 = function(test) { test.equal(null, err); // Insert a bunch of documents for the testing - collection.insert([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {safe:true}, function(err, result) { + collection.insert([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}, function(err, result) { test.equal(null, err); // Peform a simple find and return all the documents @@ -1661,7 +1661,7 @@ exports.shouldPeformASimpleLimitSkipFindWithFields2 = function(test) { */ exports.shouldPerformQueryWithBatchSizeDifferentToStandard = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1676,7 +1676,7 @@ exports.shouldPerformQueryWithBatchSizeDifferentToStandard = function(test) { } // Insert a bunch of documents for the testing - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { test.equal(null, err); // Peform a simple find and return all the documents @@ -1697,7 +1697,7 @@ exports.shouldPerformQueryWithBatchSizeDifferentToStandard = function(test) { */ exports.shouldQueryCurrentOperation = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1719,7 +1719,7 @@ exports.shouldQueryCurrentOperation = function(test) { */ exports.shouldCorrectlyPerformNegativeLimit = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1732,7 +1732,7 @@ exports.shouldCorrectlyPerformNegativeLimit = function(test) { } // Insert a bunch of documents - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { // Peform a simple find and return all the documents collection.find({}).limit(-10).toArray(function(err, docs) { test.equal(null, err); @@ -1751,7 +1751,7 @@ exports.shouldCorrectlyPerformNegativeLimit = function(test) { */ exports.shouldCorrectlyExecuteExhaustQuery = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1768,7 +1768,7 @@ exports.shouldCorrectlyExecuteExhaustQuery = function(test) { } // Insert a bunch of documents - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { // Peform a simple find and return all the documents collection.find({}, {exhaust:true}).toArray(function(err, docs2) { test.equal(null, err); @@ -1784,7 +1784,7 @@ exports.shouldCorrectlyExecuteExhaustQuery = function(test) { exports['Readpreferences should work fine when using a single server instance'] = function(test) { var server = new Server("127.0.0.1", 27017, {auto_reconnect: false, poolSize: 4, ssl:useSSL, readPreference:ReadPreference.PRIMARY_PREFERRED}); - var db = new Db('integration_tests', server, {safe:false, native_parser: native_parser, readPreference:ReadPreference.PRIMARY_PREFERRED}); + var db = new Db('integration_tests', server, {w:0, native_parser: native_parser, readPreference:ReadPreference.PRIMARY_PREFERRED}); // Establish connection to db db.open(function(err, db) { @@ -1801,7 +1801,7 @@ exports['Readpreferences should work fine when using a single server instance'] // Create a collection we want to drop later db.collection('Readpreferencesshouldworkfine', function(err, collection) { // Insert a bunch of documents - collection.insert(docs, {safe:true}, function(err, result) { + collection.insert(docs, {w:1}, function(err, result) { // Peform a simple find and return all the documents collection.find({}, {exhaust:true}).toArray(function(err, docs2) { test.equal(null, err); @@ -1817,7 +1817,7 @@ exports['Readpreferences should work fine when using a single server instance'] exports['Each should not hang on iterating over no results'] = function(test) { var server = new Server("127.0.0.1", 27017, {auto_reconnect: false, poolSize: 4, ssl:useSSL, readPreference:ReadPreference.PRIMARY_PREFERRED}); - var db = new Db('not_existing', server, {safe:false, native_parser: native_parser, readPreference:ReadPreference.PRIMARY_PREFERRED}); + var db = new Db('not_existing', server, {w:0, native_parser: native_parser, readPreference:ReadPreference.PRIMARY_PREFERRED}); // Establish connection to db db.open(function(err, db) { diff --git a/test/geo_search_test.js b/test/geo_search_test.js index 86ccecea0b..09129e8fab 100644 --- a/test/geo_search_test.js +++ b/test/geo_search_test.js @@ -25,7 +25,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -61,7 +61,7 @@ exports.tearDown = function(callback) { */ exports.shouldCorrectlyPerformSimpleGeoNearCommand = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {safe:false, auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {w:0, auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -73,7 +73,7 @@ exports.shouldCorrectlyPerformSimpleGeoNearCommand = function(test) { collection.ensureIndex({loc:"2d"}, function(err, result) { // Save a new location tagged document - collection.insert([{a:1, loc:[50, 30]}, {a:1, loc:[30, 50]}], {safe:true}, function(err, result) { + collection.insert([{a:1, loc:[50, 30]}, {a:1, loc:[30, 50]}], {w:1}, function(err, result) { // Use geoNear command to find document collection.geoNear(50, 50, {query:{a:1}, num:1}, function(err, docs) { @@ -97,7 +97,7 @@ exports.shouldCorrectlyPerformSimpleGeoNearCommand = function(test) { */ exports.shouldCorrectlyPerformSimpleGeoHaystackSearchCommand = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -109,7 +109,7 @@ exports.shouldCorrectlyPerformSimpleGeoHaystackSearchCommand = function(test) { collection.ensureIndex({loc: "geoHaystack", type: 1}, {bucketSize: 1}, function(err, result) { // Save a new location tagged document - collection.insert([{a:1, loc:[50, 30]}, {a:1, loc:[30, 50]}], {safe:true}, function(err, result) { + collection.insert([{a:1, loc:[50, 30]}, {a:1, loc:[30, 50]}], {w:1}, function(err, result) { // Use geoNear command to find document collection.geoHaystackSearch(50, 50, {search:{a:1}, limit:1, maxDistance:100}, function(err, docs) { diff --git a/test/gridstore/grid_store_file_test.js b/test/gridstore/grid_store_file_test.js index 67169601b0..8531bd94f7 100644 --- a/test/gridstore/grid_store_file_test.js +++ b/test/gridstore/grid_store_file_test.js @@ -16,7 +16,7 @@ var testCase = require('nodeunit').testCase, Server = mongodb.Server; var MONGODB = 'integration_tests'; -var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); +var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var useSSL = process.env['USE_SSL'] != null ? true : false; var native_parser = (process.env['TEST_NATIVE'] != null); @@ -67,7 +67,7 @@ exports.shouldCorrectlyFailDueToMissingChunks = function(test) { "aliases" : null, "metadata" : {}, "md5" : "4e638392b289870da9291a242e474930"}, - {safe:true}, function(err, result) { + {w:1}, function(err, result) { new mongodb.GridStore(client, FILE, "r").open(function (err, gs) { gs.read(function(err, data) { test.ok(err != null); @@ -201,7 +201,7 @@ exports.shouldCorrectlyOverwriteFile = function(test) { */ exports.shouldCorrectlySeekWithBuffer = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -389,7 +389,7 @@ exports.shouldCorrectlySeekWithString = function(test) { */ exports.shouldCorrectlySeekAcrossChunks = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); test.expect(2); // Establish connection to db @@ -435,7 +435,7 @@ exports.shouldCorrectlySeekAcrossChunks = function(test) { * @ignore */ exports.shouldCorrectlyAppendToFile = function(test) { - var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); fs_client.open(function(err, fs_client) { fs_client.dropDatabase(function(err, done) { var id = new ObjectID(); @@ -481,7 +481,7 @@ exports.shouldCorrectlyAppendToFile = function(test) { */ exports.shouldCorrectlyRewingAndTruncateOnWrite = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -534,7 +534,7 @@ exports.shouldCorrectlyRewingAndTruncateOnWrite = function(test) { * @ignore */ exports.shouldCorrectlySaveEmptyFile = function(test) { - var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); fs_client.open(function(err, fs_client) { fs_client.dropDatabase(function(err, done) { var gridStore = new GridStore(fs_client, "test_gs_save_empty_file", "w"); @@ -571,7 +571,7 @@ exports.shouldCorrectlySaveEmptyFile = function(test) { */ exports.shouldCorrectlyDetectEOF = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -894,7 +894,7 @@ exports.shouldNotThrowErrorOnClose = function(test) { */ exports.shouldCorrectlyExecuteGridstoreTell = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -939,7 +939,7 @@ exports.shouldCorrectlyExecuteGridstoreTell = function(test) { */ exports.shouldCorrectlyRetrieveSingleCharacterUsingGetC = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1003,7 +1003,7 @@ exports.shouldNotThrowErrorOnClose = function(test) { */ exports.shouldCorrectlyRetrieveSingleCharacterUsingGetC = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { diff --git a/test/gridstore/grid_store_stream_test.js b/test/gridstore/grid_store_stream_test.js index 3b53fb290a..8032b8ac28 100644 --- a/test/gridstore/grid_store_stream_test.js +++ b/test/gridstore/grid_store_stream_test.js @@ -16,7 +16,7 @@ var testCase = require('nodeunit').testCase, Server = mongodb.Server; var MONGODB = 'integration_tests'; -var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); +var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var useSSL = process.env['USE_SSL'] != null ? true : false; var native_parser = (process.env['TEST_NATIVE'] != null); @@ -175,7 +175,7 @@ exports.shouldCorrectlyWriteLargeFileBufferAndReadBack = function(test) { */ exports.shouldCorrectlyReadFileUsingStream = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -237,7 +237,7 @@ exports.shouldCorrectlyReadFileUsingStream = function(test) { */ exports.shouldCorrectlyPipeAGridFsToAfile = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { diff --git a/test/gridstore/grid_store_test.js b/test/gridstore/grid_store_test.js index ff2924c5e5..233207187f 100644 --- a/test/gridstore/grid_store_test.js +++ b/test/gridstore/grid_store_test.js @@ -16,7 +16,7 @@ var testCase = require('nodeunit').testCase, var MONGODB = 'integration_tests'; // var MONGODB = 'ruby-test-db'; -var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); +var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var useSSL = process.env['USE_SSL'] != null ? true : false; var native_parser = (process.env['TEST_NATIVE'] != null); @@ -59,7 +59,7 @@ exports.tearDown = function(callback) { */ exports.shouldCreateNewGridStoreObject = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); var gs1 , gs2 @@ -96,7 +96,7 @@ exports.shouldCreateNewGridStoreObject = function(test) { */ exports.shouldCorrectlyExecuteGridStoreExistsByObjectId = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -193,7 +193,7 @@ exports.shouldCorrectlyExecuteGridStoreExists = function(test) { */ exports.shouldCorrectlyExecuteGridStoreList = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -332,7 +332,7 @@ exports.shouldCorrectlyReadFromFileWithOffset = function(test) { * @ignore */ exports.shouldCorrectlyHandleMultipleChunkGridStore = function(test) { - var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); fs_client.open(function(err, fs_client) { fs_client.dropDatabase(function(err, done) { var gridStore = new GridStore(fs_client, "test_gs_multi_chunk", "w"); @@ -377,7 +377,7 @@ exports.shouldCorrectlyHandleMultipleChunkGridStore = function(test) { */ exports.shouldCorrectlyReadlinesAndPutLines = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -408,7 +408,7 @@ exports.shouldCorrectlyReadlinesAndPutLines = function(test) { * @ignore */ exports.shouldCorrectlyHandleUnlinkingWeirdName = function(test) { - var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); fs_client.open(function(err, fs_client) { fs_client.dropDatabase(function(err, done) { var gridStore = new GridStore(fs_client, "9476700.937375426_1271170118964-clipped.png", "w", {'root':'articles'}); @@ -460,7 +460,7 @@ exports.shouldCorrectlyHandleUnlinkingWeirdName = function(test) { */ exports.shouldCorrectlyUnlink = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -519,7 +519,7 @@ exports.shouldCorrectlyUnlink = function(test) { * @ignore */ exports.shouldCorrectlyUnlinkAnArrayOfFiles = function(test) { - var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); fs_client.open(function(err, fs_client) { fs_client.dropDatabase(function(err, done) { var gridStore = new GridStore(fs_client, "test_gs_unlink_as_array", "w"); @@ -820,7 +820,7 @@ exports.shouldCorrectlyReadAndWriteFile = function(test) { */ exports.shouldCorrectlyWriteAndReadJpgImage = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1022,7 +1022,7 @@ exports.shouldCheckExistsByUsingRegexp = function(test) { */ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingFilename = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1063,7 +1063,7 @@ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingFilename = function(test) { */ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingObjectID = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1107,7 +1107,7 @@ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingObjectID = function(test) { */ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingWriteFile = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1150,7 +1150,7 @@ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingWriteFile = function(test) */ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingWriteFileWithHandle = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1196,7 +1196,7 @@ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingWriteFileWithHandle = funct */ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingWriteWithStringsAndBuffers = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1241,7 +1241,7 @@ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingWriteWithStringsAndBuffers */ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingClose = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1278,7 +1278,7 @@ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingClose = function(test) { */ exports.shouldCorrectlyAccessChunkCollection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1312,7 +1312,7 @@ exports.shouldCorrectlyAccessChunkCollection = function(test) { */ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingCloseAndThenUnlinkIt = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1364,7 +1364,7 @@ exports.shouldCorrectlySaveSimpleFileToGridStoreUsingCloseAndThenUnlinkIt = func */ exports.shouldCorrectlyAccessFilesCollection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1398,7 +1398,7 @@ exports.shouldCorrectlyAccessFilesCollection = function(test) { */ exports.shouldCorrectlyPutACoupleOfLinesInGridStoreAndUseReadlines = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1447,7 +1447,7 @@ exports.shouldCorrectlyPutACoupleOfLinesInGridStoreAndUseReadlines = function(te */ exports.shouldCorrectlyPutACoupleOfLinesInGridStoreAndUseInstanceReadlines = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1501,7 +1501,7 @@ exports.shouldCorrectlyPutACoupleOfLinesInGridStoreAndUseInstanceReadlines = fun */ exports.shouldCorrectlyPutACoupleOfLinesInGridStoreRead = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1537,7 +1537,7 @@ exports.shouldCorrectlyOpenGridStoreWithDifferentRoot = function(test) { var asset = {source:new ObjectID()}; var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { diff --git a/test/gridstore/grid_test.js b/test/gridstore/grid_test.js index 437cfcc55c..bab6f54cbf 100644 --- a/test/gridstore/grid_test.js +++ b/test/gridstore/grid_test.js @@ -14,7 +14,7 @@ var testCase = require('nodeunit').testCase, Server = mongodb.Server; var MONGODB = 'integration_tests'; -var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); +var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var useSSL = process.env['USE_SSL'] != null ? true : false; var native_parser = (process.env['TEST_NATIVE'] != null); @@ -61,7 +61,7 @@ exports.tearDown = function(callback) { */ exports.shouldPutFileCorrectlyToGridUsingObjectId = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -91,7 +91,7 @@ exports.shouldPutFileCorrectlyToGridUsingObjectId = function(test) { */ exports.shouldPutAndGetFileCorrectlyToGridUsingObjectId = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -139,7 +139,7 @@ exports.shouldFailToPutFileDueToDataObjectNotBeingBuffer = function(test) { */ exports.shouldCorrectlyWriteFileAndThenDeleteIt = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { diff --git a/test/gridstore/gridstore_direct_streaming_test.js b/test/gridstore/gridstore_direct_streaming_test.js index ae748ee15b..02c0ca01f3 100644 --- a/test/gridstore/gridstore_direct_streaming_test.js +++ b/test/gridstore/gridstore_direct_streaming_test.js @@ -13,7 +13,7 @@ var testCase = require('nodeunit').testCase, Server = mongodb.Server; var MONGODB = 'integration_tests'; -var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); +var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var useSSL = process.env['USE_SSL'] != null ? true : false; var native_parser = (process.env['TEST_NATIVE'] != null); diff --git a/test/gridstore/readstream_test.js b/test/gridstore/readstream_test.js index 80f2f1f61d..f0ab2fe6fd 100644 --- a/test/gridstore/readstream_test.js +++ b/test/gridstore/readstream_test.js @@ -17,7 +17,7 @@ var testCase = require('nodeunit').testCase, var MONGODB = 'integration_tests'; var useSSL = process.env['USE_SSL'] != null ? true : false; -var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); +var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); var native_parser = (process.env['TEST_NATIVE'] != null); /** @@ -63,7 +63,7 @@ exports.tearDown = function(callback) { */ exports.shouldStreamDocumentsUsingTheReadStreamPauseFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -122,7 +122,7 @@ exports.shouldStreamDocumentsUsingTheReadStreamPauseFunction = function(test) { */ exports.shouldStreamDocumentsUsingTheReadStreamResumeFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -197,7 +197,7 @@ exports.shouldStreamDocumentsUsingTheReadStreamResumeFunction = function(test) { */ exports.shouldStreamDocumentsUsingTheReadStreamDestroyFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 1, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { diff --git a/test/index_test.js b/test/index_test.js index 57e2bfda04..36ee87e1dd 100644 --- a/test/index_test.js +++ b/test/index_test.js @@ -24,7 +24,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -59,7 +59,7 @@ exports.tearDown = function(callback) { */ exports.shouldCreateASimpleIndexOnASingleField = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -69,11 +69,11 @@ exports.shouldCreateASimpleIndexOnASingleField = function(test) { test.equal(null, err); // Insert a bunch of documents for the index - collection.insert([{a:1}, {a:2}, {a:3}, {a:4}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {a:2}, {a:3}, {a:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field - collection.createIndex('a', {safe:true}, function(err, indexName) { + collection.createIndex('a', {w:1}, function(err, indexName) { test.equal("a_1", indexName); // Peform a query, with explain to show we hit the query @@ -97,7 +97,7 @@ exports.shouldCreateASimpleIndexOnASingleField = function(test) { */ exports.shouldCreateComplexIndexOnTwoFields = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -108,12 +108,12 @@ exports.shouldCreateComplexIndexOnTwoFields = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field collection.createIndex({a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Show that duplicate records got dropped collection.find({}).toArray(function(err, items) { @@ -144,7 +144,7 @@ exports.shouldCreateComplexIndexOnTwoFields = function(test) { */ exports.shouldCreateComplexEnsureIndex = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -155,12 +155,12 @@ exports.shouldCreateComplexEnsureIndex = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field collection.ensureIndex({a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Show that duplicate records got dropped collection.find({}).toArray(function(err, items) { @@ -191,7 +191,7 @@ exports.shouldCreateComplexEnsureIndex = function(test) { */ exports.shouldCorrectlyShowTheResultsFromIndexInformation = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -202,12 +202,12 @@ exports.shouldCorrectlyShowTheResultsFromIndexInformation = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field collection.ensureIndex({a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Fetch basic indexInformation for collection collection.indexInformation(function(err, indexInformation) { @@ -237,7 +237,7 @@ exports.shouldCorrectlyShowTheResultsFromIndexInformation = function(test) { */ exports.shouldCorrectlyCreateAndDropIndex = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -248,12 +248,12 @@ exports.shouldCorrectlyCreateAndDropIndex = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field collection.ensureIndex({a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Drop the index collection.dropIndex("a_1_b_1", function(err, result) { @@ -282,7 +282,7 @@ exports.shouldCorrectlyCreateAndDropIndex = function(test) { */ exports.shouldCorrectlyCreateAndDropAllIndex = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -293,16 +293,16 @@ exports.shouldCorrectlyCreateAndDropAllIndex = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field collection.ensureIndex({a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Create an additional index collection.ensureIndex({c:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Drop the index collection.dropAllIndexes(function(err, result) { @@ -333,7 +333,7 @@ exports.shouldCorrectlyCreateAndDropAllIndex = function(test) { */ exports.shouldCorrectlyForceReindexOnCollection = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -344,12 +344,12 @@ exports.shouldCorrectlyForceReindexOnCollection = function(test) { // Insert a bunch of documents for the index collection.insert([{a:1, b:1}, {a:1, b:1} - , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {safe:true}, function(err, result) { + , {a:2, b:2}, {a:3, b:3}, {a:4, b:4, c:4}], {w:1}, function(err, result) { test.equal(null, err); // Create an index on the a field collection.ensureIndex({a:1, b:1} - , {unique:true, background:true, dropDups:true, safe:true}, function(err, indexName) { + , {unique:true, background:true, dropDups:true, w:1}, function(err, indexName) { // Force a reindex of the collection collection.reIndex(function(err, result) { @@ -376,9 +376,9 @@ exports.shouldCorrectlyForceReindexOnCollection = function(test) { */ exports.shouldCorrectlyExtractIndexInformation = function(test) { client.createCollection('test_index_information', function(err, collection) { - collection.insert({a:1}, {safe:true}, function(err, ids) { + collection.insert({a:1}, {w:1}, function(err, ids) { // Create an index on the collection - client.createIndex(collection.collectionName, 'a', {safe:true}, function(err, indexName) { + client.createIndex(collection.collectionName, 'a', {w:1}, function(err, indexName) { test.equal("a_1", indexName); // Let's fetch the index information client.indexInformation(collection.collectionName, function(err, collectionInfo) { @@ -418,7 +418,7 @@ exports.shouldCorrectlyHandleMultipleColumnIndexes = function(test) { client.createCollection('test_multiple_index_cols', function(err, collection) { collection.insert({a:1}, function(err, ids) { // Create an index on the collection - client.createIndex(collection.collectionName, [['a', -1], ['b', 1], ['c', -1]], {safe:true}, function(err, indexName) { + client.createIndex(collection.collectionName, [['a', -1], ['b', 1], ['c', -1]], {w:1}, function(err, indexName) { test.equal("a_-1_b_1_c_-1", indexName); // Let's fetch the index information client.indexInformation(collection.collectionName, function(err, collectionInfo) { @@ -445,9 +445,9 @@ exports.shouldCorrectlyHandleMultipleColumnIndexes = function(test) { exports.shouldCorrectlyHandleUniqueIndex = function(test) { // Create a non-unique index and test inserts client.createCollection('test_unique_index', function(err, collection) { - client.createIndex(collection.collectionName, 'hello', {safe:true}, function(err, indexName) { + client.createIndex(collection.collectionName, 'hello', {w:1}, function(err, indexName) { // Insert some docs - collection.insert([{'hello':'world'}, {'hello':'mike'}, {'hello':'world'}], {safe:true}, function(err, errors) { + collection.insert([{'hello':'world'}, {'hello':'mike'}, {'hello':'world'}], {w:1}, function(err, errors) { // Assert that we have no erros client.error(function(err, errors) { test.equal(1, errors.length); @@ -455,9 +455,9 @@ exports.shouldCorrectlyHandleUniqueIndex = function(test) { // Create a unique index and test that insert fails client.createCollection('test_unique_index2', function(err, collection) { - client.createIndex(collection.collectionName, 'hello', {unique:true, safe:true}, function(err, indexName) { + client.createIndex(collection.collectionName, 'hello', {unique:true, w:1}, function(err, indexName) { // Insert some docs - collection.insert([{'hello':'world'}, {'hello':'mike'}, {'hello':'world'}], {safe:true}, function(err, ids) { + collection.insert([{'hello':'world'}, {'hello':'mike'}, {'hello':'world'}], {w:1}, function(err, ids) { test.ok(err != null); test.equal(11000, err.code); test.done(); @@ -476,7 +476,7 @@ exports.shouldCorrectlyHandleUniqueIndex = function(test) { exports.shouldCorrectlyCreateSubfieldIndex = function(test) { // Create a non-unique index and test inserts client.createCollection('test_index_on_subfield', function(err, collection) { - collection.insert([{'hello': {'a':4, 'b':5}}, {'hello': {'a':7, 'b':2}}, {'hello': {'a':4, 'b':10}}], {safe:true}, function(err, ids) { + collection.insert([{'hello': {'a':4, 'b':5}}, {'hello': {'a':7, 'b':2}}, {'hello': {'a':4, 'b':10}}], {w:1}, function(err, ids) { // Assert that we have no erros client.error(function(err, errors) { test.equal(1, errors.length); @@ -484,8 +484,8 @@ exports.shouldCorrectlyCreateSubfieldIndex = function(test) { // Create a unique subfield index and test that insert fails client.createCollection('test_index_on_subfield2', function(err, collection) { - client.createIndex(collection.collectionName, 'hello.a', {safe:true, unique:true}, function(err, indexName) { - collection.insert([{'hello': {'a':4, 'b':5}}, {'hello': {'a':7, 'b':2}}, {'hello': {'a':4, 'b':10}}], {safe:true}, function(err, ids) { + client.createIndex(collection.collectionName, 'hello.a', {w:1, unique:true}, function(err, indexName) { + collection.insert([{'hello': {'a':4, 'b':5}}, {'hello': {'a':7, 'b':2}}, {'hello': {'a':4, 'b':10}}], {w:1}, function(err, ids) { // Assert that we have erros test.ok(err != null); test.done(); @@ -502,9 +502,9 @@ exports.shouldCorrectlyCreateSubfieldIndex = function(test) { */ exports.shouldCorrectlyDropIndexes = function(test) { client.createCollection('test_drop_indexes', function(err, collection) { - collection.insert({a:1}, {safe:true}, function(err, ids) { + collection.insert({a:1}, {w:1}, function(err, ids) { // Create an index on the collection - client.createIndex(collection.collectionName, 'a', {safe:true}, function(err, indexName) { + client.createIndex(collection.collectionName, 'a', {w:1}, function(err, indexName) { test.equal("a_1", indexName); // Drop all the indexes collection.dropAllIndexes(function(err, result) { @@ -528,7 +528,7 @@ exports.shouldThrowErrorOnAttemptingSafeCreateIndexWithNoCallback = function(tes try { // insert a doc - collection.createIndex({a:1}, {safe:true}); + collection.createIndex({a:1}, {w:1}); test.ok(false); } catch(err) {} @@ -544,7 +544,7 @@ exports.shouldThrowErrorOnAttemptingSafeEnsureIndexWithNoCallback = function(tes try { // insert a doc - collection.ensureIndex({a:1}, {safe:true}); + collection.ensureIndex({a:1}, {w:1}); test.ok(false); } catch(err) {} @@ -561,7 +561,7 @@ exports.shouldCorrectlyHandleDistinctIndexes = function(test) { collection.insert([{'a':0, 'b':{'c':'a'}}, {'a':1, 'b':{'c':'b'}}, {'a':1, 'b':{'c':'c'}}, - {'a':2, 'b':{'c':'a'}}, {'a':3}, {'a':3}], {safe:true}, function(err, ids) { + {'a':2, 'b':{'c':'a'}}, {'a':3}, {'a':3}], {w:1}, function(err, ids) { collection.distinct('a', function(err, docs) { test.deepEqual([0, 1, 2, 3], docs.sort()); }); @@ -580,7 +580,7 @@ exports.shouldCorrectlyHandleDistinctIndexes = function(test) { exports.shouldCorrectlyExecuteEnsureIndex = function(test) { client.createCollection('test_ensure_index', function(err, collection) { // Create an index on the collection - client.ensureIndex(collection.collectionName, 'a', {safe:true}, function(err, indexName) { + client.ensureIndex(collection.collectionName, 'a', {w:1}, function(err, indexName) { test.equal("a_1", indexName); // Let's fetch the index information client.indexInformation(collection.collectionName, function(err, collectionInfo) { @@ -589,7 +589,7 @@ exports.shouldCorrectlyExecuteEnsureIndex = function(test) { test.ok(collectionInfo['a_1'] != null); test.deepEqual([["a", 1]], collectionInfo['a_1']); - client.ensureIndex(collection.collectionName, 'a', {safe:true}, function(err, indexName) { + client.ensureIndex(collection.collectionName, 'a', {w:1}, function(err, indexName) { test.equal("a_1", indexName); // Let's fetch the index information client.indexInformation(collection.collectionName, function(err, collectionInfo) { @@ -613,8 +613,8 @@ exports.shouldCorrectlyCreateAndUseSparseIndex = function(test) { client.createCollection('create_and_use_sparse_index_test', function(err, r) { client.collection('create_and_use_sparse_index_test', function(err, collection) { - collection.ensureIndex({title:1}, {sparse:true, safe:true}, function(err, indexName) { - collection.insert([{name:"Jim"}, {name:"Sarah", title:"Princess"}], {safe:true}, function(err, result) { + collection.ensureIndex({title:1}, {sparse:true, w:1}, function(err, indexName) { + collection.insert([{name:"Jim"}, {name:"Sarah", title:"Princess"}], {w:1}, function(err, result) { collection.find({title:{$ne:null}}).sort({title:1}).toArray(function(err, items) { test.equal(1, items.length); test.equal("Sarah", items[0].name); @@ -639,10 +639,10 @@ exports["Should correctly execute insert with keepGoing option on mongod >= 1.9. client.admin().serverInfo(function(err, result){ if(parseInt((result.version.replace(/\./g, ''))) >= 191) { client.createCollection('shouldCorrectlyExecuteKeepGoingWithMongodb191OrHigher', function(err, collection) { - collection.ensureIndex({title:1}, {unique:true, safe:true}, function(err, indexName) { - collection.insert([{name:"Jim"}, {name:"Sarah", title:"Princess"}], {safe:true}, function(err, result) { + collection.ensureIndex({title:1}, {unique:true, w:1}, function(err, indexName) { + collection.insert([{name:"Jim"}, {name:"Sarah", title:"Princess"}], {w:1}, function(err, result) { // Force keep going flag, ignoring unique index issue - collection.insert([{name:"Jim"}, {name:"Sarah", title:"Princess"}, {name:'Gump', title:"Gump"}], {safe:true, keepGoing:true}, function(err, result) { + collection.insert([{name:"Jim"}, {name:"Sarah", title:"Princess"}, {name:'Gump', title:"Gump"}], {w:1, keepGoing:true}, function(err, result) { collection.count(function(err, count) { test.equal(3, count); test.done(); @@ -665,10 +665,10 @@ exports.shouldCorrectlyHandleGeospatialIndexes = function(test) { if(parseInt((result.version.replace(/\./g, ''))) >= 191) { client.createCollection('geospatial_index_test', function(err, r) { client.collection('geospatial_index_test', function(err, collection) { - collection.ensureIndex({loc:'2d'}, {safe:true}, function(err, indexName) { - collection.insert({'loc': [-100,100]}, {safe:true}, function(err, result) { + collection.ensureIndex({loc:'2d'}, {w:1}, function(err, indexName) { + collection.insert({'loc': [-100,100]}, {w:1}, function(err, result) { test.equal(err,null); - collection.insert({'loc': [200,200]}, {safe:true}, function(err, result) { + collection.insert({'loc': [200,200]}, {w:1}, function(err, result) { err = err ? err : {}; test.ok(err.err.indexOf("point not in interval of") != -1); test.ok(err.err.indexOf("-180") != -1); @@ -693,12 +693,12 @@ exports.shouldCorrectlyHandleGeospatialIndexesAlteredRange = function(test) { if(parseInt((result.version.replace(/\./g, ''))) >= 191) { client.createCollection('geospatial_index_altered_test', function(err, r) { client.collection('geospatial_index_altered_test', function(err, collection) { - collection.ensureIndex({loc:'2d'},{min:0,max:1024, safe:true}, function(err, indexName) { - collection.insert({'loc': [100,100]}, {safe:true}, function(err, result) { + collection.ensureIndex({loc:'2d'},{min:0,max:1024, w:1}, function(err, indexName) { + collection.insert({'loc': [100,100]}, {w:1}, function(err, result) { test.equal(err,null); - collection.insert({'loc': [200,200]}, {safe:true}, function(err, result) { + collection.insert({'loc': [200,200]}, {w:1}, function(err, result) { test.equal(err,null); - collection.insert({'loc': [-200,-200]}, {safe:true}, function(err, result) { + collection.insert({'loc': [-200,-200]}, {w:1}, function(err, result) { err = err ? err : {}; test.ok(err.err.indexOf("point not in interval of") != -1); test.ok(err.err.indexOf("0") != -1); @@ -721,10 +721,10 @@ exports.shouldCorrectlyHandleGeospatialIndexesAlteredRange = function(test) { */ exports.shouldThrowDuplicateKeyErrorWhenCreatingIndex = function(test) { client.createCollection('shouldThrowDuplicateKeyErrorWhenCreatingIndex', function(err, collection) { - collection.insert([{a:1}, {a:1}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {a:1}], {w:1}, function(err, result) { test.equal(null, err); - collection.ensureIndex({a:1}, {unique:true, safe:true}, function(err, indexName) { + collection.ensureIndex({a:1}, {unique:true, w:1}, function(err, indexName) { test.ok(err != null); test.done(); }); @@ -737,14 +737,14 @@ exports.shouldThrowDuplicateKeyErrorWhenCreatingIndex = function(test) { */ exports.shouldThrowDuplicateKeyErrorWhenDriverInStrictMode = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser, strict:true}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser, strict:true}); // Establish connection to db db.open(function(err, db) { db.createCollection('shouldThrowDuplicateKeyErrorWhenDriverInStrictMode', function(err, collection) { - collection.insert([{a:1}, {a:1}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {a:1}], {w:1}, function(err, result) { test.equal(null, err); - collection.ensureIndex({a:1}, {unique:true, safe:true}, function(err, indexName) { + collection.ensureIndex({a:1}, {unique:true, w:1}, function(err, indexName) { test.ok(err != null); db.close(); test.done(); @@ -762,10 +762,10 @@ exports.shouldCorrectlyUseMinMaxForSettingRangeInEnsureIndex = function(test) { client.createCollection('shouldCorrectlyUseMinMaxForSettingRangeInEnsureIndex', function(err, collection) { test.equal(null, err); - collection.ensureIndex({loc:'2d'}, {min:200, max:1400, safe:true}, function(err, indexName) { + collection.ensureIndex({loc:'2d'}, {min:200, max:1400, w:1}, function(err, indexName) { test.equal(null, err); - collection.insert({loc:[600, 600]}, {safe:true}, function(err, result) { + collection.insert({loc:[600, 600]}, {w:1}, function(err, result) { test.equal(null, err); test.done(); }); diff --git a/test/insert_test.js b/test/insert_test.js index a7906cf982..623ae6d9e1 100644 --- a/test/insert_test.js +++ b/test/insert_test.js @@ -71,7 +71,7 @@ var ISODate = function (string) { */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -107,7 +107,7 @@ exports.tearDown = function(callback) { */ exports.shouldCorrectlyPerformASimpleSingleDocumentInsertNoCallbackNoSafe = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -140,7 +140,7 @@ exports.shouldCorrectlyPerformASimpleSingleDocumentInsertNoCallbackNoSafe = func */ exports.shouldCorrectlyPerformABatchDocumentInsertSafe = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -150,7 +150,7 @@ exports.shouldCorrectlyPerformABatchDocumentInsertSafe = function(test) { // Insert a single document collection.insert([{hello:'world_safe1'} - , {hello:'world_safe2'}], {safe:true}, function(err, result) { + , {hello:'world_safe2'}], {w:1}, function(err, result) { test.equal(null, err); // Fetch the document @@ -174,7 +174,7 @@ exports.shouldCorrectlyPerformABatchDocumentInsertSafe = function(test) { */ exports.shouldCorrectlyPerformASimpleDocumentInsertWithFunctionSafe = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -184,7 +184,7 @@ exports.shouldCorrectlyPerformASimpleDocumentInsertWithFunctionSafe = function(t // Insert a single document collection.insert({hello:'world' - , func:function() {}}, {safe:true, serializeFunctions:true}, function(err, result) { + , func:function() {}}, {w:1, serializeFunctions:true}, function(err, result) { test.equal(null, err); // Fetch the document @@ -208,7 +208,7 @@ exports.shouldCorrectlyPerformASimpleDocumentInsertWithFunctionSafe = function(t */ exports["Should correctly execute insert with keepGoing option on mongod >= 1.9.1"] = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -227,12 +227,12 @@ exports["Should correctly execute insert with keepGoing option on mongod >= 1.9. // Insert some intial data into the collection collection.insert([{name:"Jim"} - , {name:"Sarah", title:"Princess"}], {safe:true}, function(err, result) { + , {name:"Sarah", title:"Princess"}], {w:1}, function(err, result) { // Force keep going flag, ignoring unique index issue collection.insert([{name:"Jim"} , {name:"Sarah", title:"Princess"} - , {name:'Gump', title:"Gump"}], {safe:true, keepGoing:true}, function(err, result) { + , {name:'Gump', title:"Gump"}], {w:1, keepGoing:true}, function(err, result) { // Count the number of documents left (should not include the duplicates) collection.count(function(err, count) { @@ -257,7 +257,7 @@ exports["Should correctly execute insert with keepGoing option on mongod >= 1.9. */ exports.shouldForceMongoDbServerToAssignId = function(test) { /// Set up server with custom pk factory - var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null), 'forceServerObjectId':true}); + var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null), 'forceServerObjectId':true}); db.open(function(err, client) { client.createCollection('test_insert2', function(err, r) { client.collection('test_insert2', function(err, collection) { @@ -267,13 +267,13 @@ exports.shouldForceMongoDbServerToAssignId = function(test) { var group = this.group(); for(var i = 1; i < 1000; i++) { - collection.insert({c:i}, {safe:true}, group()); + collection.insert({c:i}, {w:1}, group()); } }, function done(err, result) { - collection.insert({a:2}, {safe:true}, function(err, r) { - collection.insert({a:3}, {safe:true}, function(err, r) { + collection.insert({a:2}, {w:1}, function(err, r) { + collection.insert({a:3}, {w:1}, function(err, r) { collection.count(function(err, count) { test.equal(1001, count); // Locate all the entries using find @@ -300,7 +300,7 @@ exports.shouldForceMongoDbServerToAssignId = function(test) { */ exports.shouldCorrectlyPerformSingleInsert = function(test) { client.createCollection('shouldCorrectlyPerformSingleInsert', function(err, collection) { - collection.insert({a:1}, {safe:true}, function(err, result) { + collection.insert({a:1}, {w:1}, function(err, result) { collection.findOne(function(err, item) { test.equal(1, item.a); test.done(); @@ -321,13 +321,13 @@ exports.shouldCorrectlyPerformBasicInsert = function(test) { var group = this.group(); for(var i = 1; i < 1000; i++) { - collection.insert({c:i}, {safe:true}, group()); + collection.insert({c:i}, {w:1}, group()); } }, function done(err, result) { - collection.insert({a:2}, {safe:true}, function(err, r) { - collection.insert({a:3}, {safe:true}, function(err, r) { + collection.insert({a:2}, {w:1}, function(err, r) { + collection.insert({a:3}, {w:1}, function(err, r) { collection.count(function(err, count) { test.equal(1001, count); // Locate all the entries using find @@ -355,7 +355,7 @@ exports.shouldCorrectlyHandleMultipleDocumentInsert = function(test) { var collection = client.collection('test_multiple_insert', function(err, collection) { var docs = [{a:1}, {a:2}]; - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { ids.forEach(function(doc) { test.ok(((doc['_id']) instanceof ObjectID || Object.prototype.toString.call(doc['_id']) === '[object ObjectID]')); }); @@ -382,12 +382,12 @@ exports.shouldCorrectlyHandleMultipleDocumentInsert = function(test) { */ exports.shouldCorrectlyExecuteSaveInsertUpdate= function(test) { client.createCollection('shouldCorrectlyExecuteSaveInsertUpdate', function(err, collection) { - collection.save({ email : 'save' }, {safe:true}, function() { - collection.insert({ email : 'insert' }, {safe:true}, function() { + collection.save({ email : 'save' }, {w:1}, function() { + collection.insert({ email : 'insert' }, {w:1}, function() { collection.update( { email : 'update' }, { email : 'update' }, - { upsert: true, safe:true}, + { upsert: true, w:1}, function() { collection.find().toArray(function(e, a) { @@ -410,7 +410,7 @@ exports.shouldCorrectlyInsertAndRetrieveLargeIntegratedArrayDocument = function( 'b':['tmp1', 'tmp2', 'tmp3', 'tmp4', 'tmp5', 'tmp6', 'tmp7', 'tmp8', 'tmp9', 'tmp10', 'tmp11', 'tmp12', 'tmp13', 'tmp14', 'tmp15', 'tmp16'] }; // Insert the collection - collection.insert(doc, {safe:true}, function(err, r) { + collection.insert(doc, {w:1}, function(err, r) { // Fetch and check the collection collection.findOne({'a': 0}, function(err, result) { test.deepEqual(doc.a, result.a); @@ -450,7 +450,7 @@ exports.shouldCorrectlyInsertAndRetrieveDocumentWithAllTypes = function(test) { 'dbref': new DBRef('namespace', oid, 'integration_tests_') } - collection.insert(motherOfAllDocuments, {safe:true}, function(err, docs) { + collection.insert(motherOfAllDocuments, {w:1}, function(err, docs) { collection.findOne(function(err, doc) { // Assert correct deserialization of the values test.equal(motherOfAllDocuments.string, doc.string); @@ -484,7 +484,7 @@ exports.shouldCorrectlyInsertAndRetrieveDocumentWithAllTypes = function(test) { * @ignore */ exports.shouldCorrectlyInsertAndUpdateDocumentWithNewScriptContext= function(test) { - var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, db) { //convience curried handler for functions of type 'a -> (err, result) function getResult(callback){ @@ -495,10 +495,10 @@ exports.shouldCorrectlyInsertAndUpdateDocumentWithNewScriptContext= function(tes }; db.collection('users', getResult(function(user_collection){ - user_collection.remove({}, {safe:true}, function(err, result) { + user_collection.remove({}, {w:1}, function(err, result) { //first, create a user object var newUser = { name : 'Test Account', settings : {} }; - user_collection.insert([newUser], {safe:true}, getResult(function(users){ + user_collection.insert([newUser], {w:1}, getResult(function(users){ var user = users[0]; var scriptCode = "settings.block = []; settings.block.push('test');"; @@ -509,7 +509,7 @@ exports.shouldCorrectlyInsertAndUpdateDocumentWithNewScriptContext= function(tes //now create update command and issue it var updateCommand = { $set : context }; - user_collection.update({_id : user._id}, updateCommand, {safe:true}, + user_collection.update({_id : user._id}, updateCommand, {w:1}, getResult(function(updateCommand) { // Fetch the object and check that the changes are persisted user_collection.findOne({_id : user._id}, function(err, doc) { @@ -571,7 +571,7 @@ exports.shouldCorrectlySerializeDocumentWithAllTypesInNewContext = function(test // sys.puts(sys.inspect(context.motherOfAllDocuments)) var motherOfAllDocuments = context.motherOfAllDocuments; - collection.insert(context.motherOfAllDocuments, {safe:true}, function(err, docs) { + collection.insert(context.motherOfAllDocuments, {w:1}, function(err, docs) { collection.findOne(function(err, doc) { // Assert correct deserialization of the values test.equal(motherOfAllDocuments.string, doc.string); @@ -607,7 +607,7 @@ exports.shouldCorrectlyDoToJsonForLongValue = function(test) { client.createCollection('test_to_json_for_long', function(err, collection) { test.ok(collection instanceof Collection); - collection.insert([{value: Long.fromNumber(32222432)}], {safe:true}, function(err, ids) { + collection.insert([{value: Long.fromNumber(32222432)}], {w:1}, function(err, ids) { collection.findOne({}, function(err, item) { test.equal(32222432, item.value); test.done(); @@ -620,7 +620,7 @@ exports.shouldCorrectlyDoToJsonForLongValue = function(test) { * @ignore */ exports.shouldCorrectlyInsertAndUpdateWithNoCallback = function(test) { - var db = new Db(MONGODB, new Server('localhost', 27017, {safe:false, auto_reconnect: true, poolSize: 1, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server('localhost', 27017, {w:0, auto_reconnect: true, poolSize: 1, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, client) { client.createCollection('test_insert_and_update_no_callback', function(err, collection) { // Insert the update @@ -647,13 +647,13 @@ exports.shouldCorrectlyInsertAndUpdateWithNoCallback = function(test) { */ exports.shouldInsertAndQueryTimestamp = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { db.createCollection('test_insert_and_query_timestamp', function(err, collection) { // Insert the update - collection.insert({i:Timestamp.fromNumber(100), j:Long.fromNumber(200)}, {safe:true}, function(err, r) { + collection.insert({i:Timestamp.fromNumber(100), j:Long.fromNumber(200)}, {w:1}, function(err, r) { // Locate document collection.findOne({}, function(err, item) { test.ok(item.i instanceof Timestamp); @@ -675,7 +675,7 @@ exports.shouldInsertAndQueryTimestamp = function(test) { exports.shouldCorrectlyInsertAndQueryUndefined = function(test) { client.createCollection('test_insert_and_query_undefined', function(err, collection) { // Insert the update - collection.insert({i:undefined}, {safe:true}, function(err, r) { + collection.insert({i:undefined}, {w:1}, function(err, r) { // Locate document collection.findOne({}, function(err, item) { test.equal(null, item.i) @@ -714,7 +714,7 @@ exports.shouldCorrectlyPerformSafeInsert = function(test) { var group = this.group(); for(var i = 0; i < fixtures.length; i++) { - collection.insert(fixtures[i], {safe:true}, group()); + collection.insert(fixtures[i], {w:1}, group()); } }, @@ -751,7 +751,7 @@ exports.shouldThrowErrorIfSerializingFunction = function(test) { client.createCollection('test_should_throw_error_if_serializing_function', function(err, collection) { var func = function() { return 1}; // Insert the update - collection.insert({i:1, z:func }, {safe:true, serializeFunctions:true}, function(err, result) { + collection.insert({i:1, z:func }, {w:1, serializeFunctions:true}, function(err, result) { collection.findOne({_id:result[0]._id}, function(err, object) { test.equal(func.toString(), object.z.code); test.equal(1, object.i); @@ -766,7 +766,7 @@ exports.shouldThrowErrorIfSerializingFunction = function(test) { */ exports.shouldCorrectlyInsertDocumentWithUUID = function(test) { client.collection("insert_doc_with_uuid", function(err, collection) { - collection.insert({_id : "12345678123456781234567812345678", field: '1'}, {safe:true}, function(err, result) { + collection.insert({_id : "12345678123456781234567812345678", field: '1'}, {w:1}, function(err, result) { test.equal(null, err); collection.find({_id : "12345678123456781234567812345678"}).toArray(function(err, items) { @@ -777,7 +777,7 @@ exports.shouldCorrectlyInsertDocumentWithUUID = function(test) { // Generate a binary id var binaryUUID = new Binary('00000078123456781234567812345678', Binary.SUBTYPE_UUID); - collection.insert({_id : binaryUUID, field: '2'}, {safe:true}, function(err, result) { + collection.insert({_id : binaryUUID, field: '2'}, {w:1}, function(err, result) { collection.find({_id : binaryUUID}).toArray(function(err, items) { test.equal(null, err); test.equal(items[0].field, '2') @@ -793,10 +793,10 @@ exports.shouldCorrectlyInsertDocumentWithUUID = function(test) { * @ignore */ exports.shouldCorrectlyCallCallbackWithDbDriverInStrictMode = function(test) { - var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, poolSize: 1, ssl:useSSL}), {safe:true, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, poolSize: 1, ssl:useSSL}), {w:1, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, client) { client.createCollection('test_insert_and_update_no_callback_strict', function(err, collection) { - collection.insert({_id : "12345678123456781234567812345678", field: '1'}, {safe:true}, function(err, result) { + collection.insert({_id : "12345678123456781234567812345678", field: '1'}, {w:1}, function(err, result) { test.equal(null, err); collection.update({ '_id': "12345678123456781234567812345678" }, { '$set': { 'field': 0 }}, function(err, numberOfUpdates) { @@ -819,12 +819,12 @@ exports.shouldCorrectlyInsertDBRefWithDbNotDefined = function(test) { var doc = {_id: new ObjectID()}; var doc2 = {_id: new ObjectID()}; var doc3 = {_id: new ObjectID()}; - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { // Create object with dbref doc2.ref = new DBRef('shouldCorrectlyInsertDBRefWithDbNotDefined', doc._id); doc3.ref = new DBRef('shouldCorrectlyInsertDBRefWithDbNotDefined', doc._id, MONGODB); - collection.insert([doc2, doc3], {safe:true}, function(err, result) { + collection.insert([doc2, doc3], {w:1}, function(err, result) { // Get all items collection.find().toArray(function(err, items) { test.equal("shouldCorrectlyInsertDBRefWithDbNotDefined", items[1].ref.namespace); @@ -846,16 +846,16 @@ exports.shouldCorrectlyInsertDBRefWithDbNotDefined = function(test) { * @ignore */ exports.shouldCorrectlyInsertUpdateRemoveWithNoOptions = function(test) { - var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, db) { db.collection('shouldCorrectlyInsertUpdateRemoveWithNoOptions', function(err, collection) { - collection.insert({a:1}, {safe:true}, function(err, result) { + collection.insert({a:1}, {w:1}, function(err, result) { test.equal(null, err); - collection.update({a:1}, {a:2}, {safe:true}, function(err, result) { + collection.update({a:1}, {a:2}, {w:1}, function(err, result) { test.equal(null, err); - collection.remove({a:2}, {safe:true}, function(err, result) { + collection.remove({a:2}, {w:1}, function(err, result) { test.equal(null, err); collection.count(function(err, count) { @@ -875,13 +875,13 @@ exports.shouldCorrectlyInsertUpdateRemoveWithNoOptions = function(test) { * @ignore */ exports.shouldCorrectlyExecuteMultipleFetches = function(test) { - var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, new Server('localhost', 27017, {auto_reconnect: true, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Search parameter var to = 'ralph' // Execute query db.open(function(err, db) { db.collection('shouldCorrectlyExecuteMultipleFetches', function(err, collection) { - collection.insert({addresses:{localPart:'ralph'}}, {safe:true}, function(err, result) { + collection.insert({addresses:{localPart:'ralph'}}, {w:1}, function(err, result) { // Let's find our user collection.findOne({"addresses.localPart" : to}, function( err, doc ) { test.equal(null, err); @@ -900,7 +900,7 @@ exports.shouldCorrectlyExecuteMultipleFetches = function(test) { */ exports.shouldCorrectlyFailWhenNoObjectToUpdate= function(test) { client.createCollection('shouldCorrectlyExecuteSaveInsertUpdate', function(err, collection) { - collection.update({_id : new ObjectID()}, { email : 'update' }, {safe:true}, + collection.update({_id : new ObjectID()}, { email : 'update' }, {w:1}, function(err, result) { test.equal(0, result); test.done(); @@ -924,7 +924,7 @@ exports['Should correctly insert object and retrieve it when containing array an } client.createCollection('Should_correctly_insert_object_and_retrieve_it_when_containing_array_and_IsoDate', function(err, collection) { - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.ok(err == null); collection.findOne(function(err, item) { @@ -952,7 +952,7 @@ exports['Should correctly insert object with timestamps'] = function(test) { } client.createCollection('Should_correctly_insert_object_with_timestamps', function(err, collection) { - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.ok(err == null); collection.findOne(function(err, item) { @@ -974,7 +974,7 @@ exports['Should fail on insert due to key starting with $'] = function(test) { } client.createCollection('Should_fail_on_insert_due_to_key_starting_with', function(err, collection) { - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.ok(err != null); test.done(); }); @@ -993,9 +993,9 @@ exports['Should Correctly allow for control of serialization of functions on com client.createCollection("Should_Correctly_allow_for_control_of_serialization_of_functions_on_command_level", function(err, collection) { test.ok(err == null); - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { - collection.update({str:"String"}, {$set:{c:1, d:function(){}}}, {safe:true, serializeFunctions:false}, function(err, result) { + collection.update({str:"String"}, {$set:{c:1, d:function(){}}}, {w:1, serializeFunctions:false}, function(err, result) { test.equal(1, result); collection.findOne({str:"String"}, function(err, item) { @@ -1024,7 +1024,7 @@ exports['Should Correctly allow for control of serialization of functions on col client.createCollection("Should_Correctly_allow_for_control_of_serialization_of_functions_on_collection_level", {serializeFunctions:true}, function(err, collection) { test.ok(err == null); - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.equal(null, err); collection.findOne({str : "String"}, function(err, item) { @@ -1047,7 +1047,7 @@ exports['Should Correctly allow for using a Date object as _id'] = function(test client.createCollection("Should_Correctly_allow_for_using_a_Date_object_as__id", {serializeFunctions:true}, function(err, collection) { test.ok(err == null); - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.equal(null, err); collection.findOne({str : "hello"}, function(err, item) { @@ -1065,7 +1065,7 @@ exports['Should Correctly fail to update returning 0 results'] = function(test) client.createCollection("Should_Correctly_fail_to_update_returning_0_results", {serializeFunctions:true}, function(err, collection) { test.ok(err == null); - collection.update({a:1}, {$set: {a:1}}, {safe:true}, function(err, numberOfUpdated) { + collection.update({a:1}, {$set: {a:1}}, {w:1}, function(err, numberOfUpdated) { test.equal(0, numberOfUpdated); test.done(); }); @@ -1088,11 +1088,11 @@ exports['Should Correctly update two fields including a sub field'] = function(t } client.createCollection("Should_Correctly_update_two_fields_including_a_sub_field", {}, function(err, collection) { - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.equal(null, err); // Update two fields - collection.update({_id:doc._id}, {$set:{Prop1:'p1_2', 'More.Sub2':'s2_2'}}, {safe:true}, function(err, numberOfUpdatedDocs) { + collection.update({_id:doc._id}, {$set:{Prop1:'p1_2', 'More.Sub2':'s2_2'}}, {w:1}, function(err, numberOfUpdatedDocs) { test.equal(null, err); test.equal(1, numberOfUpdatedDocs); @@ -1112,11 +1112,11 @@ exports['Should Correctly update two fields including a sub field'] = function(t */ exports['Should correctly fail due to duplicate key for _id'] = function(test) { client.createCollection("Should_Correctly_update_two_fields_including_a_sub_field_2", {}, function(err, collection) { - collection.insert({_id:1}, {safe:true}, function(err, result) { + collection.insert({_id:1}, {w:1}, function(err, result) { test.equal(null, err); // Update two fields - collection.insert({_id:1}, {safe:true}, function(err, result) { + collection.insert({_id:1}, {w:1}, function(err, result) { test.ok(err != null); test.done(); }); @@ -1130,7 +1130,7 @@ exports['Should correctly fail due to duplicate key for _id'] = function(test) { exports.shouldCorrectlyInsertDocWithCustomId = function(test) { client.createCollection('shouldCorrectlyInsertDocWithCustomId', function(err, collection) { // Insert the update - collection.insert({_id:0, test:'hello'}, {safe:true}, function(err, result) { + collection.insert({_id:0, test:'hello'}, {w:1}, function(err, result) { test.equal(null, err); collection.findOne({_id:0}, function(err, item) { @@ -1149,7 +1149,7 @@ exports.shouldFailDueToInsertBeingBiggerThanMaxDocumentSizeAllowed = function(te var binary = new Binary(new Buffer(client.serverConfig.checkoutWriter().maxBsonSize + 100)); // Create a collection client.createCollection('shouldFailDueToInsertBeingBiggerThanMaxDocumentSizeAllowed', function(err, collection) { - collection.insert({doc:binary}, {safe:true}, function(err, result) { + collection.insert({doc:binary}, {w:1}, function(err, result) { test.ok(err != null); test.equal(null, result); test.done(); @@ -1163,14 +1163,14 @@ exports.shouldFailDueToInsertBeingBiggerThanMaxDocumentSizeAllowed = function(te exports.shouldCorrectlyPerformUpsertAgainstNewDocumentAndExistingOne = function(test) { client.createCollection('shouldCorrectlyPerformUpsertAgainstNewDocumentAndExistingOne', function(err, collection) { // Upsert a new doc - collection.update({a:1}, {a:1}, {upsert:true, safe:true}, function(err, result, status) { + collection.update({a:1}, {a:1}, {upsert:true, w:1}, function(err, result, status) { test.equal(1, result); test.equal(false, status.updatedExisting); test.equal(1, status.n); test.ok(status.upserted != null); // Upsert an existing doc - collection.update({a:1}, {a:1}, {upsert:true, safe:true}, function(err, result, status) { + collection.update({a:1}, {a:1}, {upsert:true, w:1}, function(err, result, status) { test.equal(1, result); test.equal(true, status.updatedExisting); test.equal(1, status.n); @@ -1192,7 +1192,7 @@ exports.shouldCorrectlyPerformLargeTextInsert = function(test) { string = string + "a"; } - collection.insert({a:1, string:string}, {safe:true}, function(err, result) { + collection.insert({a:1, string:string}, {w:1}, function(err, result) { test.equal(null, err); collection.findOne({a:1}, function(err, doc) { @@ -1213,7 +1213,7 @@ exports.shouldCorrectlyPerformInsertOfObjectsUsingToBSON = function(test) { var doc = {a:1, b:1}; doc.toBSON = function() { return {c:this.a}}; - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.equal(null, err); collection.findOne({c:1}, function(err, doc) { @@ -1230,7 +1230,7 @@ exports.shouldCorrectlyPerformInsertOfObjectsUsingToBSON = function(test) { */ exports.shouldAttempToForceBsonSize = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL, disableDriverBSONSizeCheck:true}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL, disableDriverBSONSizeCheck:true}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -1242,7 +1242,7 @@ exports.shouldAttempToForceBsonSize = function(test) { {a:1, b:new Binary(new Buffer(16777216/2))}, ] - collection.insert(doc, {safe:true}, function(err, result) { + collection.insert(doc, {w:1}, function(err, result) { test.equal(null, err); collection.findOne({a:1}, function(err, doc) { @@ -1262,7 +1262,7 @@ exports.shouldAttempToForceBsonSize = function(test) { */ exports.shouldCorrectlyUseCustomObjectToUpdateDocument = function(test) { client.createCollection('shouldCorrectlyExecuteSaveInsertUpdate', function(err, collection) { - collection.insert({a:{b:{c:1}}}, {safe:true}, function(err, result) { + collection.insert({a:{b:{c:1}}}, {w:1}, function(err, result) { test.equal(null, err); // Dynamically build query @@ -1272,7 +1272,7 @@ exports.shouldCorrectlyUseCustomObjectToUpdateDocument = function(test) { query.a.b['c'] = 1; // Update document - collection.update(query, {$set: {'a.b.d':1}}, {safe:true}, function(err, numberUpdated) { + collection.update(query, {$set: {'a.b.d':1}}, {w:1}, function(err, numberUpdated) { test.equal(null, err); test.equal(1, numberUpdated); diff --git a/test/logging_test.js b/test/logging_test.js index 723cf8e92c..f502311550 100644 --- a/test/logging_test.js +++ b/test/logging_test.js @@ -22,7 +22,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -64,7 +64,7 @@ exports.shouldCorrectlyLogContent = function(test) { } } - var automatic_connect_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null), retryMiliSeconds:50, logger:logger}); + var automatic_connect_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null), retryMiliSeconds:50, logger:logger}); automatic_connect_client.open(function(err, automatic_connect_client) { automatic_connect_client.close(); test.equal(true, loggedOutput); diff --git a/test/manual_tests/find_modify_break_test.js b/test/manual_tests/find_modify_break_test.js index d4fddb5da1..de36edd5cc 100644 --- a/test/manual_tests/find_modify_break_test.js +++ b/test/manual_tests/find_modify_break_test.js @@ -27,7 +27,7 @@ db.open(function(err, client) { console.log('findAndModify request (should not be last)'); - collection.findAndModify({hello: 'world'}, [['_id', 'asc']], {$set: {hi: 'there'}},{safe:true, upsert:true}, function(err, object) { + collection.findAndModify({hello: 'world'}, [['_id', 'asc']], {$set: {hi: 'there'}},{w:1, upsert:true}, function(err, object) { if (err) { console.warn('findAndModify error response ', err.message); // returns error if no matching object found } else { diff --git a/test/manual_tests/manual_ha_test.js b/test/manual_tests/manual_ha_test.js index c309a4e49c..cbbf78aaf8 100644 --- a/test/manual_tests/manual_ha_test.js +++ b/test/manual_tests/manual_ha_test.js @@ -33,11 +33,11 @@ RS.startSet(true, function(err, result) { db.collection('stats', function(statsErr, stats) { if (statsErr) return console.log('error opening stats %o', err); - stats.remove({}, {safe:true}, function(err, result) { + stats.remove({}, {w:1}, function(err, result) { console.log("================================================================") console.dir(err) - stats.insert({name:'reqcount', value:0}, {safe:true}, function(err, result) { + stats.insert({name:'reqcount', value:0}, {w:1}, function(err, result) { console.log("================================================================") console.dir(err) //create server diff --git a/test/manual_tests/manual_larger_queries.js b/test/manual_tests/manual_larger_queries.js index 09aceeb8db..bb2d3d9876 100644 --- a/test/manual_tests/manual_larger_queries.js +++ b/test/manual_tests/manual_larger_queries.js @@ -87,10 +87,10 @@ RS.startSet(true, function(err, result) { } // Insert all the docs - userCollection.insert(userDocs, {safe:true}, function(err, result) { + userCollection.insert(userDocs, {w:1}, function(err, result) { console.dir(err); - accountCollection.insert(accountDocs, {safe:true}, function(err, result) { + accountCollection.insert(accountDocs, {w:1}, function(err, result) { console.dir(err); var timeoutFunc = function() { diff --git a/test/manual_tests/manual_lock.js b/test/manual_tests/manual_lock.js index 33da8bec3f..5c724e4953 100644 --- a/test/manual_tests/manual_lock.js +++ b/test/manual_tests/manual_lock.js @@ -36,12 +36,12 @@ RS.startSet(true, function(err, result) { client.collection("collA", function(err, coll){ collA = coll; - coll.insert(userObjects, {safe:true}, function(err, result) { + coll.insert(userObjects, {w:1}, function(err, result) { client.collection("collB", function(err, coll){ collB = coll; - coll.insert(userObjects, {safe:true}, function(err, result) { + coll.insert(userObjects, {w:1}, function(err, result) { var timeoutFunc = function() { lookup(function(err, result) { diff --git a/test/manual_tests/replicaset_manual_kill_test.js b/test/manual_tests/replicaset_manual_kill_test.js index a27ef46b8f..5ed3341ddc 100644 --- a/test/manual_tests/replicaset_manual_kill_test.js +++ b/test/manual_tests/replicaset_manual_kill_test.js @@ -32,11 +32,11 @@ RS.startSet(true, function(err, result) { db.collection('stats', function(statsErr, stats) { if (statsErr) return console.log('error opening stats %o', err); - stats.remove({}, {safe:true}, function(err, result) { + stats.remove({}, {w:1}, function(err, result) { console.log("================================================================") console.dir(err) - stats.insert({name:'reqcount', value:0}, {safe:true}, function(err, result) { + stats.insert({name:'reqcount', value:0}, {w:1}, function(err, result) { console.log("================================================================") console.dir(err) //create server diff --git a/test/manual_tests/replicaset_test.js b/test/manual_tests/replicaset_test.js index fc61965a0d..6487b54172 100644 --- a/test/manual_tests/replicaset_test.js +++ b/test/manual_tests/replicaset_test.js @@ -45,7 +45,7 @@ RS.startSet(true, function(err, result) { } client.collection("users", function(err, coll){ - coll.insert(userObjects, {safe:true}, function(err, result) { + coll.insert(userObjects, {w:1}, function(err, result) { users = coll; query(); }) diff --git a/test/manual_tests/single_test.js b/test/manual_tests/single_test.js index 662b921e92..eced64bf3c 100644 --- a/test/manual_tests/single_test.js +++ b/test/manual_tests/single_test.js @@ -37,8 +37,8 @@ db.open(function(err, client){ } client.collection("users", function(err, coll){ - coll.remove({}, {safe:true}, function(err) { - coll.insert(userObjects, {safe:true}, function(err, result) { + coll.remove({}, {w:1}, function(err) { + coll.insert(userObjects, {w:1}, function(err, result) { users = coll; query(); }) diff --git a/test/manual_tests/tailable_cursor_test.js b/test/manual_tests/tailable_cursor_test.js index 09f6f8f8f7..11ba4ded94 100644 --- a/test/manual_tests/tailable_cursor_test.js +++ b/test/manual_tests/tailable_cursor_test.js @@ -19,7 +19,7 @@ _db.open(function(err, db) { // db.dropCollection("tailableCollection", function(err, result) { // Set up tailable cursor - db.createCollection("tailableCollection", {safe:true, capped:true, size: 100000}, function(err, collection) { + db.createCollection("tailableCollection", {w:1, capped:true, size: 100000}, function(err, collection) { console.log("======================== ++++++++++++++++++++++++++++++++++++++++"); // db.collection("tailableCollection").find({}, {tailable:true, tailableRetryInterval:1000}).each(function(err, item) { diff --git a/test/manual_tests/test.js b/test/manual_tests/test.js index 006668b3d0..9b62aec3fe 100644 --- a/test/manual_tests/test.js +++ b/test/manual_tests/test.js @@ -48,7 +48,7 @@ RS.startSet(true, function(err, result) { client.collection("users", function(err, coll){ console.log("Connected"); - coll.insert(userObjects, {safe:true}, function(err, result) { + coll.insert(userObjects, {w:1}, function(err, result) { users = coll; query(); }) diff --git a/test/map_reduce_test.js b/test/map_reduce_test.js index 35cdd7eba7..c12b5bad70 100644 --- a/test/map_reduce_test.js +++ b/test/map_reduce_test.js @@ -25,7 +25,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -61,7 +61,7 @@ if(!process.env['TEST_COVERAGE']) { */ exports.shouldCorrectlyExecuteGroupFunction = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -74,7 +74,7 @@ exports.shouldCorrectlyExecuteGroupFunction = function(test) { test.deepEqual([], results); // Trigger some inserts on the collection - collection.insert([{'a':2}, {'b':5}, {'a':1}], {safe:true}, function(err, ids) { + collection.insert([{'a':2}, {'b':5}, {'a':1}], {w:1}, function(err, ids) { // Perform a group count collection.group([], {}, {"count":0}, "function (obj, prev) { prev.count++; }", function(err, results) { @@ -95,7 +95,7 @@ exports.shouldCorrectlyExecuteGroupFunction = function(test) { test.equal(1, results[0].count); // Insert some more test data - collection.insert([{'a':2}, {'b':3}], {safe:true}, function(err, ids) { + collection.insert([{'a':2}, {'b':3}], {w:1}, function(err, ids) { // Do a Group by field a collection.group(['a'], {}, {"count":0}, "function (obj, prev) { prev.count++; }", function(err, results) { @@ -180,7 +180,7 @@ exports.shouldCorrectlyExecuteGroupFunctionWithFinalizeFunction = function(test) test.deepEqual([], results); // Trigger some inserts - collection.insert([{'a':2}, {'b':5, 'a':0}, {'a':1}, {'c':2, 'a':0}], {safe:true}, function(err, ids) { + collection.insert([{'a':2}, {'b':5, 'a':0}, {'a':1}, {'c':2, 'a':0}], {w:1}, function(err, ids) { collection.group([], {}, {count: 0, running_average: 0} , function (doc, out) { out.count++; @@ -206,7 +206,7 @@ exports.shouldCorrectlyExecuteGroupFunctionWithFinalizeFunction = function(test) */ exports.shouldPerformSimpleMapReduceFunctions = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -215,7 +215,7 @@ exports.shouldPerformSimpleMapReduceFunctions = function(test) { db.createCollection('test_map_reduce_functions', function(err, collection) { // Insert some documents to perform map reduce over - collection.insert([{'user_id':1}, {'user_id':2}], {safe:true}, function(err, r) { + collection.insert([{'user_id':1}, {'user_id':2}], {w:1}, function(err, r) { // Map function var map = function() { emit(this.user_id, 1); }; @@ -249,7 +249,7 @@ exports.shouldPerformSimpleMapReduceFunctions = function(test) { */ exports.shouldPerformMapReduceFunctionInline = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -264,7 +264,7 @@ exports.shouldPerformMapReduceFunctionInline = function(test) { db.createCollection('test_map_reduce_functions_inline', function(err, collection) { // Insert some test documents - collection.insert([{'user_id':1}, {'user_id':2}], {safe:true}, function(err, r) { + collection.insert([{'user_id':1}, {'user_id':2}], {w:1}, function(err, r) { // Map function var map = function() { emit(this.user_id, 1); }; @@ -299,7 +299,7 @@ exports.shouldPerformMapReduceFunctionInline = function(test) { */ exports.shouldPerformMapReduceInContext = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -309,7 +309,7 @@ exports.shouldPerformMapReduceInContext = function(test) { // Insert some test documents collection.insert([{'user_id':1, 'timestamp':new Date()} - , {'user_id':2, 'timestamp':new Date()}], {safe:true}, function(err, r) { + , {'user_id':2, 'timestamp':new Date()}], {w:1}, function(err, r) { // Map function var map = function(){ @@ -351,7 +351,7 @@ exports.shouldPerformMapReduceInContext = function(test) { */ exports.shouldPerformMapReduceWithStringFunctions = function(test) { client.createCollection('test_map_reduce', function(err, collection) { - collection.insert([{'user_id':1}, {'user_id':2}], {safe:true}, function(err, r) { + collection.insert([{'user_id':1}, {'user_id':2}], {w:1}, function(err, r) { // String functions var map = "function() { emit(this.user_id, 1); }"; var reduce = "function(k,vals) { return 1; }"; @@ -376,7 +376,7 @@ exports.shouldPerformMapReduceWithStringFunctions = function(test) { */ exports.shouldForceMapReduceError = function(test) { client.createCollection('test_map_reduce', function(err, collection) { - collection.insert([{'user_id':1}, {'user_id':2}], {safe:true}, function(err, r) { + collection.insert([{'user_id':1}, {'user_id':2}], {w:1}, function(err, r) { // String functions var map = "function() { emiddft(this.user_id, 1); }"; var reduce = "function(k,vals) { return 1; }"; @@ -402,7 +402,7 @@ exports.shouldForceMapReduceError = function(test) { */ exports.shouldPerformMapReduceWithParametersBeingFunctions = function(test) { client.createCollection('test_map_reduce_with_functions_as_arguments', function(err, collection) { - collection.insert([{'user_id':1}, {'user_id':2}], {safe:true}, function(err, r) { + collection.insert([{'user_id':1}, {'user_id':2}], {w:1}, function(err, r) { // String functions var map = function() { emit(this.user_id, 1); }; var reduce = function(k,vals) { return 1; }; @@ -426,7 +426,7 @@ exports.shouldPerformMapReduceWithParametersBeingFunctions = function(test) { */ exports.shouldPerformMapReduceWithCodeObjects = function(test) { client.createCollection('test_map_reduce_with_code_objects', function(err, collection) { - collection.insert([{'user_id':1}, {'user_id':2}], {safe:true}, function(err, r) { + collection.insert([{'user_id':1}, {'user_id':2}], {w:1}, function(err, r) { // String functions var map = new Code("function() { emit(this.user_id, 1); }"); var reduce = new Code("function(k,vals) { return 1; }"); @@ -450,7 +450,7 @@ exports.shouldPerformMapReduceWithCodeObjects = function(test) { */ exports.shouldPerformMapReduceWithOptions = function(test) { client.createCollection('test_map_reduce_with_options', function(err, collection) { - collection.insert([{'user_id':1}, {'user_id':2}, {'user_id':3}], {safe:true}, function(err, r) { + collection.insert([{'user_id':1}, {'user_id':2}, {'user_id':3}], {w:1}, function(err, r) { // String functions var map = new Code("function() { emit(this.user_id, 1); }"); var reduce = new Code("function(k,vals) { return 1; }"); @@ -478,7 +478,7 @@ exports.shouldPerformMapReduceWithOptions = function(test) { */ exports.shouldHandleMapReduceErrors = function(test) { client.createCollection('test_map_reduce_error', function(err, collection) { - collection.insert([{'user_id':1}, {'user_id':2}, {'user_id':3}], {safe:true}, function(err, r) { + collection.insert([{'user_id':1}, {'user_id':2}, {'user_id':3}], {w:1}, function(err, r) { // String functions var map = new Code("function() { throw 'error'; }"); var reduce = new Code("function(k,vals) { throw 'error'; }"); @@ -496,7 +496,7 @@ exports.shouldHandleMapReduceErrors = function(test) { */ exports.shouldSaveDataToDifferentDbFromMapreduce = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -505,7 +505,7 @@ exports.shouldSaveDataToDifferentDbFromMapreduce = function(test) { db.createCollection('test_map_reduce_functions', function(err, collection) { // Insert some documents to perform map reduce over - collection.insert([{'user_id':1}, {'user_id':2}], {safe:true}, function(err, r) { + collection.insert([{'user_id':1}, {'user_id':2}], {w:1}, function(err, r) { // Map function var map = function() { emit(this.user_id, 1); }; @@ -567,7 +567,7 @@ exports.shouldCorrectlyReturnNestedKeys = function(test) { lastname:'smith', date:new Date() } - }, {safe:true}, function(err, result) { + }, {w:1}, function(err, result) { // Execute the group collection.group(keys, condition, initial, reduce, true, function(err, r) { diff --git a/test/mongo_client_test.js b/test/mongo_client_test.js index 4d2cd61b64..55dbc2e7f9 100644 --- a/test/mongo_client_test.js +++ b/test/mongo_client_test.js @@ -24,7 +24,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db diff --git a/test/mongo_reply_test.js b/test/mongo_reply_test.js index 6328e37d0c..417f3bd842 100644 --- a/test/mongo_reply_test.js +++ b/test/mongo_reply_test.js @@ -33,7 +33,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db diff --git a/test/multiple_dbs_on_connection_pool_test.js b/test/multiple_dbs_on_connection_pool_test.js index 19a227e630..09da2573ae 100644 --- a/test/multiple_dbs_on_connection_pool_test.js +++ b/test/multiple_dbs_on_connection_pool_test.js @@ -24,7 +24,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -58,7 +58,7 @@ exports.shouldCorrectlyEmitErrorOnAllDbsOnPoolClose = function(test) { if(process.env['JENKINS']) return test.done(); if(process.platform !== 'linux') { - var db = new Db('tests', new Server("127.0.0.1", 27027, {auto_reconnect: true}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('tests', new Server("127.0.0.1", 27027, {auto_reconnect: true}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // All inserted docs var docs = []; var errs = []; @@ -76,7 +76,7 @@ exports.shouldCorrectlyEmitErrorOnAllDbsOnPoolClose = function(test) { db.createCollection('shouldCorrectlyErrorOnAllDbs', function(err, collection) { test.equal(null, err); - collection.insert({a:1}, {safe:true}, function(err, result) { + collection.insert({a:1}, {w:1}, function(err, result) { test.equal(null, err); // Open a second db @@ -108,7 +108,7 @@ exports.shouldCorrectlyEmitErrorOnAllDbsOnPoolClose = function(test) { * @ignore */ exports.shouldCorrectlyUseSameConnectionsForTwoDifferentDbs = function(test) { - var second_test_database = new Db(MONGODB + "_2", new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null), retryMiliSeconds:50}); + var second_test_database = new Db(MONGODB + "_2", new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null), retryMiliSeconds:50}); // Just create second database second_test_database.open(function(err, second_test_database) { // Close second database @@ -154,7 +154,7 @@ exports.shouldCorrectlyUseSameConnectionsForTwoDifferentDbs = function(test) { * @ignore */ exports.shouldCorrectlyUseSameConnectionsForTwoDifferentDbs = function(test) { - var second_test_database = new Db(MONGODB + "_2", new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null), retryMiliSeconds:50}); + var second_test_database = new Db(MONGODB + "_2", new Server("127.0.0.1", 27017, {auto_reconnect: true, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null), retryMiliSeconds:50}); // Just create second database second_test_database.open(function(err, second_test_database) { // Close second database @@ -202,7 +202,7 @@ exports.shouldCorrectlyUseSameConnectionsForTwoDifferentDbs = function(test) { */ exports.shouldCorrectlyShareConnectionPoolsAcrossMultipleDbInstances = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -217,8 +217,8 @@ exports.shouldCorrectlyShareConnectionPoolsAcrossMultipleDbInstances = function( var multipleColl2 = secondDb.collection("multiple_db_instances"); // Write a record into each and then count the records stored - multipleColl1.insert({a:1}, {safe:true}, function(err, result) { - multipleColl2.insert({a:1}, {safe:true}, function(err, result) { + multipleColl1.insert({a:1}, {w:1}, function(err, result) { + multipleColl2.insert({a:1}, {w:1}, function(err, result) { // Count over the results ensuring only on record in each collection multipleColl1.count(function(err, count) { @@ -241,7 +241,7 @@ exports.shouldCorrectlyShareConnectionPoolsAcrossMultipleDbInstances = function( */ exports.shouldCorrectlyHandleMultipleDbsFindAndModifies = function(test) { var mongo_server = new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 1, socketOptions: {noDelay:false}}); - new Db('init_db', mongo_server, {safe:false}).open(function (error, db) { + new Db('init_db', mongo_server, {w:0}).open(function (error, db) { var db_instance = db.db('site1'); db_instance = db.db('site2'); db_instance = db.db('rss'); diff --git a/test/objectid_test.js b/test/objectid_test.js index 045e4d7dd6..2a41173794 100644 --- a/test/objectid_test.js +++ b/test/objectid_test.js @@ -23,7 +23,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -58,7 +58,7 @@ exports.shouldCorrectlyGenerateObjectID = function(test) { client.collection('test_object_id_generation.data', function(err, collection) { // Insert test documents (creates collections and test fetch by query) - collection.insert({name:"Fred", age:42}, {safe:true}, function(err, ids) { + collection.insert({name:"Fred", age:42}, {w:1}, function(err, ids) { test.equal(1, ids.length); test.ok(ids[0]['_id'].toHexString().length == 24); // Locate the first document inserted @@ -69,7 +69,7 @@ exports.shouldCorrectlyGenerateObjectID = function(test) { }); // Insert another test document and collect using ObjectId - collection.insert({name:"Pat", age:21}, {safe:true}, function(err, ids) { + collection.insert({name:"Pat", age:21}, {w:1}, function(err, ids) { test.equal(1, ids.length); test.ok(ids[0]['_id'].toHexString().length == 24); // Locate the first document inserted @@ -82,7 +82,7 @@ exports.shouldCorrectlyGenerateObjectID = function(test) { // Manually created id var objectId = new ObjectID(null); // Insert a manually created document with generated oid - collection.insert({"_id":objectId, name:"Donald", age:95}, {safe:true}, function(err, ids) { + collection.insert({"_id":objectId, name:"Donald", age:95}, {w:1}, function(err, ids) { test.equal(1, ids.length); test.ok(ids[0]['_id'].toHexString().length == 24); test.equal(objectId.toHexString(), ids[0]['_id'].toHexString()); @@ -241,7 +241,7 @@ exports.shouldCorrectlyCreateOIDNotUsingObjectID = function(test) { date.setUTCMinutes(0); date.setUTCSeconds(30); - collection.insert({'_id':date}, {safe:true}, function(err, ids) { + collection.insert({'_id':date}, {w:1}, function(err, ids) { collection.find({'_id':date}).toArray(function(err, items) { test.equal(("" + date), ("" + items[0]._id)); @@ -283,9 +283,9 @@ exports.shouldCorrectlyCreateAnObjectIDAndOverrideTheTimestamp = function(test) */ exports.shouldCorrectlyInsertWithObjectId = function(test) { client.createCollection('shouldCorrectlyInsertWithObjectId', function(err, collection) { - collection.insert({}, {safe:true}, function(err, ids) { + collection.insert({}, {w:1}, function(err, ids) { setTimeout(function() { - collection.insert({}, {safe:true}, function(err, ids) { + collection.insert({}, {w:1}, function(err, ids) { collection.find().toArray(function(err, items) { var compareDate = new Date(); diff --git a/test/raw_test.js b/test/raw_test.js index 937d052db6..9a7520310f 100644 --- a/test/raw_test.js +++ b/test/raw_test.js @@ -23,7 +23,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -53,7 +53,7 @@ exports.tearDown = function(callback) { exports.shouldCorrectlySaveDocumentsAndReturnAsRaw = function(test) { client.createCollection('shouldCorrectlySaveDocumentsAndReturnAsRaw', function(err, collection) { // Insert some documents - collection.insert([{a:1}, {b:2000}, {c:2.3}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2000}, {c:2.3}], {w:1}, function(err, result) { // You have to pass at least query + fields before passing options collection.find({}, null, {raw:true}).toArray(function(err, items) { var objects = []; @@ -81,7 +81,7 @@ exports.shouldCorrectlySaveDocumentsAndReturnAsRaw = function(test) { exports.shouldCorrectlyRemoveDocumentAndReturnRaw = function(test) { client.createCollection('shouldCorrectlyRemoveDocumentAndReturnRaw', function(err, collection) { // Insert some documents - collection.insert([{a:1}, {b:2000}, {c:2.3}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2000}, {c:2.3}], {w:1}, function(err, result) { // Let's create a raw delete command var queryObject = {b:2000}; // Create raw bson buffer @@ -89,7 +89,7 @@ exports.shouldCorrectlyRemoveDocumentAndReturnRaw = function(test) { client.bson.serializeWithBufferAndIndex(queryObject, false, rawQueryObject, 0); // Update the document and return the raw new document - collection.remove(rawQueryObject, {safe:true}, function(err, numberOfDeleted) { + collection.remove(rawQueryObject, {w:1}, function(err, numberOfDeleted) { test.equal(1, numberOfDeleted); collection.findOne({b:2000}, function(err, item) { @@ -104,7 +104,7 @@ exports.shouldCorrectlyRemoveDocumentAndReturnRaw = function(test) { exports.shouldCorrectlyUpdateDocumentAndReturnRaw = function(test) { client.createCollection('shouldCorrectlyUpdateDocumentAndReturnRaw', function(err, collection) { // Insert some documents - collection.insert([{a:1}, {b:2000}, {c:2.3}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2000}, {c:2.3}], {w:1}, function(err, result) { // Let's create a raw delete command var selectorObject = {b:2000}; // Create raw bson buffer @@ -116,7 +116,7 @@ exports.shouldCorrectlyUpdateDocumentAndReturnRaw = function(test) { var rawUpdateObject = new Buffer(client.bson.calculateObjectSize(updateObject)); client.bson.serializeWithBufferAndIndex(updateObject, false, rawUpdateObject, 0); // Update the document and return the raw new document - collection.update(rawSelectorObject, rawUpdateObject, {safe:true}, function(err, numberOfUpdated) { + collection.update(rawSelectorObject, rawUpdateObject, {w:1}, function(err, numberOfUpdated) { test.equal(1, numberOfUpdated); // Query the document @@ -154,7 +154,7 @@ exports.shouldCorreclyInsertRawDocumentAndRetrieveThem = function(test) { } // Insert all raw objects - collection.insert(serializedObjects, {safe:true}, function(err, result) { + collection.insert(serializedObjects, {w:1}, function(err, result) { test.equal(null, err); // Query the document @@ -177,7 +177,7 @@ exports.shouldCorreclyInsertRawDocumentAndRetrieveThem = function(test) { exports.shouldCorrectlyPeformQueryUsingRaw = function(test) { client.createCollection('shouldCorrectlyPeformQueryUsingRaw', function(err, collection) { - collection.insert([{a:1}, {b:2}, {b:3}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2}, {b:3}], {w:1}, function(err, result) { test.equal(null, err); // Let's create a raw query object @@ -215,7 +215,7 @@ exports.shouldCorrectlyThrowErrorsWhenIllegalySizedMessages = function(test) { client.createCollection('shouldCorrectlyThrowErrorsWhenIllegalySizedMessages', function(err, collection) { var illegalBuffer = new Buffer(20); try { - collection.insert(illegalBuffer, {safe:true}, function(err, result) {}); + collection.insert(illegalBuffer, {w:1}, function(err, result) {}); } catch (err) { test.ok(err.toString().indexOf("insert") != -1); } @@ -267,7 +267,7 @@ exports.shouldCorrectlyThrowErrorsWhenIllegalySizedMessages = function(test) { exports.shouldCorrectlyPeformQueryUsingRawSettingRawAtCollectionLevel = function(test) { client.createCollection('shouldCorrectlyPeformQueryUsingRawSettingRawAtCollectionLevel', function(err, collection) { - collection.insert([{a:1}, {b:2}, {b:3}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2}, {b:3}], {w:1}, function(err, result) { test.equal(null, err); // Let's create a raw query object @@ -318,7 +318,7 @@ exports.shouldCorreclyInsertRawDocumentAndRetrieveThemSettingRawAtCollectionLeve } // Insert all raw objects - collection.insert(serializedObjects, {safe:true}, function(err, result) { + collection.insert(serializedObjects, {w:1}, function(err, result) { test.equal(null, err); // Query the document @@ -342,7 +342,7 @@ exports.shouldCorreclyInsertRawDocumentAndRetrieveThemSettingRawAtCollectionLeve exports.shouldCorrectlyUpdateDocumentAndReturnRawSettingRawAtCollectionLevel = function(test) { client.createCollection('shouldCorrectlyUpdateDocumentAndReturnRawSettingRawAtCollectionLevel', {raw:true}, function(err, collection) { // Insert some documents - collection.insert([{a:1}, {b:2000}, {c:2.3}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2000}, {c:2.3}], {w:1}, function(err, result) { // Let's create a raw delete command var selectorObject = {b:2000}; // Create raw bson buffer @@ -354,7 +354,7 @@ exports.shouldCorrectlyUpdateDocumentAndReturnRawSettingRawAtCollectionLevel = f var rawUpdateObject = new Buffer(client.bson.calculateObjectSize(updateObject)); client.bson.serializeWithBufferAndIndex(updateObject, false, rawUpdateObject, 0); // Update the document and return the raw new document - collection.update(rawSelectorObject, rawUpdateObject, {safe:true}, function(err, numberOfUpdated) { + collection.update(rawSelectorObject, rawUpdateObject, {w:1}, function(err, numberOfUpdated) { test.equal(1, numberOfUpdated); // Query the document diff --git a/test/reaper_test.js b/test/reaper_test.js deleted file mode 100644 index 7b4a7e1dab..0000000000 --- a/test/reaper_test.js +++ /dev/null @@ -1,124 +0,0 @@ -var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure(); -var useSSL = process.env['USE_SSL'] != null ? true : false; - -var testCase = require('nodeunit').testCase, - debug = require('util').debug, - inspect = require('util').inspect, - nodeunit = require('nodeunit'), - gleak = require('../dev/tools/gleak'), - Db = mongodb.Db, - Cursor = mongodb.Cursor, - Collection = mongodb.Collection, - Server = mongodb.Server; - -var MONGODB = 'integration_tests'; -var client = null; - -/** - * Retrieve the server information for the current - * instance of the db client - * - * @ignore - */ -exports.setUp = function(callback) { - var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); - client.open(function(err, db_p) { - if(numberOfTestsRun == (Object.keys(self).length)) { - // If first test drop the db - client.dropDatabase(function(err, done) { - callback(); - }); - } else { - return callback(); - } - }); -} - -/** - * Retrieve the server information for the current - * instance of the db client - * - * @ignore - */ -exports.tearDown = function(callback) { - var self = this; - numberOfTestsRun = numberOfTestsRun - 1; - // Close connection - client.close(); - callback(); -} - -exports.shouldCorrectlyAssertCorrectReaperBehavior = function(test) { - var reaperClient = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {safe:false, reaper:true, native_parser: (process.env['TEST_NATIVE'] != null)}); - reaperClient.open(function(err, reaperClient) { - reaperClient._lastReaperTimestamp = (new Date().getTime() - 1000000); - var con = reaperClient.serverConfig.checkoutReader(); - // Prime the reaper with a bogus call - reaperClient._callBackStore._notReplied["3"] = {start: (new Date().getTime() - 50000), 'raw': false, chained:null, connection:con}; - reaperClient._callBackStore.once("3", function(err, result) { - reaperClient.close(); - test.done(); - }) - - reaperClient.collection("test", {safe:true}, function(err, col) { - // Does not matter - }); - }) -} - -// // * - **reaperInterval** {Number, default:10000}, number of miliseconds between reaper wakups. -// // * - **reaperTimeout** {Number, default:30000}, the amount of time before a callback times out. - -// exports.shouldHandleReaperKills = function(test) { -// var reaperClient = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false, ssl:useSSL}), {reaper:true, reaperInterval:0, reaperTimeout:0, native_parser: (process.env['TEST_NATIVE'] != null)}); -// reaperClient.open(function(err, db) { -// db.collection("shouldHandleReaperKills").insert({a:1}, {safe:true}, function(err, result) { -// console.log("============================================") -// db.collection("shouldHandleReaperKills").insert({a:1}, {safe:true}, function(err, result) { -// // Prime the reaper with a bogus call -// db._callBackStore._notReplied["3"] = {start: (new Date().getTime() - 50000), 'raw': false, chained:null, connection:null}; - -// db.collection("shouldHandleReaperKills").findOne(function(err, item) { -// db.close(); -// test.done(); -// }) - -// }); -// }); - - -// // reaperClient._lastReaperTimestamp = (new Date().getTime() - 1000000); -// // var con = reaperClient.serverConfig.checkoutReader(); -// // // Prime the reaper with a bogus call -// // reaperClient._callBackStore._notReplied["3"] = {start: (new Date().getTime() - 50000), 'raw': false, chained:null, connection:con}; -// // reaperClient._callBackStore.once("3", function(err, result) { -// // reaperClient.close(); -// // test.done(); -// // }) - -// // reaperClient.collection("test", {safe:true}, function(err, col) { -// // // Does not matter -// // }); -// }) -// } - -/** - * Retrieve the server information for the current - * instance of the db client - * - * @ignore - */ -exports.noGlobalsLeaked = function(test) { - var leaks = gleak.detectNew(); - test.equal(0, leaks.length, "global var leak detected: " + leaks.join(', ')); - test.done(); -} - -/** - * Retrieve the server information for the current - * instance of the db client - * - * @ignore - */ -var numberOfTestsRun = Object.keys(this).length - 2; \ No newline at end of file diff --git a/test/regexp_test.js b/test/regexp_test.js index b36f3c4d44..62b9b18e7c 100644 --- a/test/regexp_test.js +++ b/test/regexp_test.js @@ -22,7 +22,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -53,7 +53,7 @@ exports.shouldCorrectlyInsertSimpleRegExpDocument = function(test) { var regexp = /foobar/i; client.createCollection('test_regex', function(err, collection) { - collection.insert({'b':regexp}, {safe:true}, function(err, ids) { + collection.insert({'b':regexp}, {w:1}, function(err, ids) { collection.find({}, {'fields': ['b']}).toArray(function(err, items) { test.equal(("" + regexp), ("" + items[0].b)); // Let's close the db @@ -67,7 +67,7 @@ exports.shouldCorrectlyInsertSimpleUTF8Regexp = function(test) { var regexp = /foobaré/; client.createCollection('test_utf8_regex', function(err, collection) { - collection.insert({'b':regexp}, {safe:true}, function(err, ids) { + collection.insert({'b':regexp}, {w:1}, function(err, ids) { collection.find({}, {'fields': ['b']}).toArray(function(err, items) { test.equal(("" + regexp), ("" + items[0].b)); // Let's close the db @@ -81,7 +81,7 @@ exports.shouldCorrectlyFindDocumentsByRegExp = function(test) { // Serialized regexes contain extra trailing chars. Sometimes these trailing chars contain / which makes // the original regex invalid, and leads to segmentation fault. client.createCollection('test_regex_serialization', function(err, collection) { - collection.insert({keywords: ["test", "segmentation", "fault", "regex", "serialization", "native"]}, {safe:true}, function(err, r) { + collection.insert({keywords: ["test", "segmentation", "fault", "regex", "serialization", "native"]}, {w:1}, function(err, r) { var count = 20, run = function(i) { diff --git a/test/remove_test.js b/test/remove_test.js index c153db76e7..3130f7b48e 100644 --- a/test/remove_test.js +++ b/test/remove_test.js @@ -23,7 +23,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -59,7 +59,7 @@ exports.tearDown = function(callback) { */ exports.shouldRemoveAllDocumentsNoSafe = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -68,7 +68,7 @@ exports.shouldRemoveAllDocumentsNoSafe = function(test) { db.collection("remove_all_documents_no_safe", function(err, collection) { // Insert a bunch of documents - collection.insert([{a:1}, {b:2}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2}], {w:1}, function(err, result) { test.equal(null, err); // Remove all the document @@ -99,7 +99,7 @@ exports.shouldRemoveAllDocumentsNoSafe = function(test) { */ exports.shouldRemoveSubsetOfDocumentsSafeMode = function(test) { var db = new Db('integration_tests', new Server("127.0.0.1", 27017, - {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: native_parser}); + {auto_reconnect: false, poolSize: 4, ssl:useSSL}), {w:0, native_parser: native_parser}); // Establish connection to db db.open(function(err, db) { @@ -108,11 +108,11 @@ exports.shouldRemoveSubsetOfDocumentsSafeMode = function(test) { db.collection("remove_subset_of_documents_safe", function(err, collection) { // Insert a bunch of documents - collection.insert([{a:1}, {b:2}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {b:2}], {w:1}, function(err, result) { test.equal(null, err); // Remove all the document - collection.remove({a:1}, {safe:true}, function(err, numberOfRemovedDocs) { + collection.remove({a:1}, {w:1}, function(err, numberOfRemovedDocs) { test.equal(null, err); test.equal(1, numberOfRemovedDocs); db.close(); @@ -129,12 +129,12 @@ exports.shouldRemoveSubsetOfDocumentsSafeMode = function(test) { exports.shouldCorrectlyClearOutCollection = function(test) { client.createCollection('test_clear', function(err, r) { client.collection('test_clear', function(err, collection) { - collection.insert({i:1}, {safe:true}, function(err, ids) { - collection.insert({i:2}, {safe:true}, function(err, ids) { + collection.insert({i:1}, {w:1}, function(err, ids) { + collection.insert({i:2}, {w:1}, function(err, ids) { collection.count(function(err, count) { test.equal(2, count); // Clear the collection - collection.remove({}, {safe:true}, function(err, result) { + collection.remove({}, {w:1}, function(err, result) { test.equal(2, result); collection.count(function(err, count) { @@ -156,9 +156,9 @@ exports.shouldCorrectlyClearOutCollection = function(test) { exports.shouldCorrectlyRemoveDocumentUsingRegExp = function(test) { client.createCollection('test_remove_regexp', function(err, r) { client.collection('test_remove_regexp', function(err, collection) { - collection.insert({address:'485 7th ave new york'}, {safe:true}, function(err, ids) { + collection.insert({address:'485 7th ave new york'}, {w:1}, function(err, ids) { // Clear the collection - collection.remove({address:/485 7th ave/}, {safe:true}, function(err, result) { + collection.remove({address:/485 7th ave/}, {w:1}, function(err, result) { test.equal(1, result); collection.count(function(err, count) { @@ -178,11 +178,11 @@ exports.shouldCorrectlyRemoveDocumentUsingRegExp = function(test) { exports.shouldCorrectlyRemoveOnlyFirstDocument = function(test) { client.createCollection('shouldCorrectlyRemoveOnlyFirstDocument', function(err, r) { client.collection('shouldCorrectlyRemoveOnlyFirstDocument', function(err, collection) { - collection.insert([{a:1}, {a:1}, {a:1}, {a:1}], {safe:true}, function(err, result) { + collection.insert([{a:1}, {a:1}, {a:1}, {a:1}], {w:1}, function(err, result) { test.equal(null, err); // Remove the first - collection.remove({a:1}, {safe:true, single:true}, function(err, number) { + collection.remove({a:1}, {w:1, single:true}, function(err, number) { test.equal(1, number); collection.find({a:1}).count(function(err, result) { diff --git a/test/replicaset/connect_test.js b/test/replicaset/connect_test.js index 442ae5a186..bcb7688479 100644 --- a/test/replicaset/connect_test.js +++ b/test/replicaset/connect_test.js @@ -28,7 +28,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -108,8 +108,8 @@ exports.shouldThrowErrorDueToSharedConnectionUsage = function(test) { ); try { - var db = new Db(MONGODB, replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); - var db1 = new Db(MONGODB, replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(MONGODB, replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db1 = new Db(MONGODB, replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); } catch(err) { test.done(); } @@ -143,7 +143,7 @@ exports.shouldCorrectlyHandleErrorWhenNoServerUpInReplicaset = function(test) { ] ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { test.ok(err != null); test.done(); @@ -165,7 +165,7 @@ exports.shouldCorrectlyConnectWithDefaultReplicasetNoOption = function(test) { ] ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { test.equal(null, err); p_db.close(); @@ -186,7 +186,7 @@ exports.shouldCorrectlyConnectWithDefaultReplicaset = function(test) { {} ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { test.equal(null, err); test.done(); @@ -207,7 +207,7 @@ exports.shouldCorrectlyConnectWithDefaultReplicasetAndSocketOptionsSet = functio {socketOptions:{keepAlive:100}} ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { test.equal(null, err); test.equal(100, db.serverConfig.checkoutWriter().socketOptions.keepAlive) @@ -228,7 +228,7 @@ exports.shouldEmitCloseNoCallback = function(test) { ], {} ); - new Db('integration_test_', replSet, {safe:false}).open(function(err, db) { + new Db('integration_test_', replSet, {w:0}).open(function(err, db) { test.equal(null, err); var dbCloseCount = 0, serverCloseCount = 0; db.on('close', function() { ++dbCloseCount; }); @@ -253,7 +253,7 @@ exports.shouldEmitCloseWithCallback = function(test) { ], {} ); - new Db('integration_test_', replSet, {safe:false}).open(function(err, db) { + new Db('integration_test_', replSet, {w:0}).open(function(err, db) { test.equal(null, err); var dbCloseCount = 0; db.on('close', function() { ++dbCloseCount; }); @@ -281,7 +281,7 @@ exports.shouldCorrectlyPassErrorWhenWrongReplicaSet = function(test) { {rs_name:RS.name + "-wrong"} ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { test.notEqual(null, err); test.done(); @@ -305,7 +305,7 @@ exports.shouldConnectWithPrimarySteppedDown = function(test) { // Wait for new primary to pop up ensureConnection(test, retries, function(err, p_db) { - new Db('integration_test_', replSet, {safe:false}).open(function(err, p_db) { + new Db('integration_test_', replSet, {w:0}).open(function(err, p_db) { test.ok(err == null); test.equal(true, p_db.serverConfig.isConnected()); @@ -336,7 +336,7 @@ exports.shouldConnectWithThirdNodeKilled = function(test) { // Wait for new primary to pop up ensureConnection(test, retries, function(err, p_db) { - new Db('integration_test_', replSet, {safe:false}).open(function(err, p_db) { + new Db('integration_test_', replSet, {w:0}).open(function(err, p_db) { test.ok(err == null); test.equal(true, p_db.serverConfig.isConnected()); @@ -363,7 +363,7 @@ exports.shouldConnectWithSecondaryNodeKilled = function(test) { {rs_name:RS.name} ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= caught error") @@ -397,7 +397,7 @@ exports.shouldConnectWithPrimaryNodeKilled = function(test) { {rs_name:RS.name} ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); ensureConnection(test, retries, function(err, p_db) { if(err != null && err.stack != null) console.log(err.stack) test.done(); @@ -418,7 +418,7 @@ exports.shouldCorrectlyBeAbleToUsePortAccessors = function(test) { {rs_name:RS.name} ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { if(err != null) debug("shouldCorrectlyBeAbleToUsePortAccessors :: " + inspect(err)); test.equal(replSet.host, p_db.serverConfig.primary.host); @@ -451,7 +451,7 @@ exports.shouldCorrectlyConnect = function(test) { {rs_name:RS.name, connectArbiter:true} ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { if(err != null) debug("shouldCorrectlyConnect :: " + inspect(err)); test.equal(true, p_db.serverConfig.isConnected()); @@ -480,7 +480,7 @@ exports.shouldCorrectlyConnect = function(test) { return item.host + ":" + item.port; }).sort()); // Force new instance - var db2 = new Db('integration_test_', replSet2, {safe:false}); + var db2 = new Db('integration_test_', replSet2, {w:0}); db2.open(function(err, p_db2) { if(err != null) debug("shouldCorrectlyConnect :: " + inspect(err)); @@ -510,7 +510,7 @@ exports.shouldCorrectlyEmitOpenSignalAndFullSetSignal = function(test) { {rs_name:RS.name} ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.once("open", function(_err, _db) { openCalled = true; }); diff --git a/test/replicaset/count_test.js b/test/replicaset/count_test.js index 9e2678c828..d334ea7fb3 100644 --- a/test/replicaset/count_test.js +++ b/test/replicaset/count_test.js @@ -27,7 +27,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -105,7 +105,7 @@ exports.shouldRetrieveCorrectCountAfterInsertionReconnect = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { // if(err != null) debug("shouldRetrieveCorrectCountAfterInsertionReconnect :: " + inspect(err)); // Drop collection on replicaset @@ -135,10 +135,10 @@ exports.shouldRetrieveCorrectCountAfterInsertionReconnect = function(test) { p_db.collection('testsets', function(err, collection) { if(err != null) debug("shouldRetrieveCorrectCountAfterInsertionReconnect :: " + inspect(err)); - collection.insert({a:30}, {safe:true}, function(err, r) { + collection.insert({a:30}, {w:1}, function(err, r) { if(err != null) debug("shouldRetrieveCorrectCountAfterInsertionReconnect :: " + inspect(err)); - collection.insert({a:40}, {safe:true}, function(err, r) { + collection.insert({a:40}, {w:1}, function(err, r) { if(err != null) debug("shouldRetrieveCorrectCountAfterInsertionReconnect :: " + inspect(err)); // Execute count diff --git a/test/replicaset/insert_and_query_on_dead_primary_test.js b/test/replicaset/insert_and_query_on_dead_primary_test.js index 5249f674c9..e9e0e3bacd 100644 --- a/test/replicaset/insert_and_query_on_dead_primary_test.js +++ b/test/replicaset/insert_and_query_on_dead_primary_test.js @@ -27,7 +27,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -103,7 +103,7 @@ exports.shouldNotTimeout = function (test) { {} ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { test.equal(null, err); @@ -114,7 +114,7 @@ exports.shouldNotTimeout = function (test) { RS.killPrimary(2, function(node) { var pending = 2; - coll.update({name: 'a'}, {'$inc': {v: 1}}, {upsert: true, safe:true}, done); + coll.update({name: 'a'}, {'$inc': {v: 1}}, {upsert: true, w:1}, done); coll.findOne({name: 'a'}, done); function done (err, result) { diff --git a/test/replicaset/insert_test.js b/test/replicaset/insert_test.js index e8b0212c3c..35eab7de3d 100644 --- a/test/replicaset/insert_test.js +++ b/test/replicaset/insert_test.js @@ -72,7 +72,7 @@ exports.shouldCorrectlyWaitForReplicationToServersOnInserts = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false, numberOfRetries:20, retryMiliSeconds:5000}); + var db = new Db('integration_test_', replSet, {w:0, numberOfRetries:20, retryMiliSeconds:5000}); db.open(function(err, p_db) { // Drop collection on replicaset p_db.dropCollection('shouldCorrectlyWaitForReplicationToServersOnInserts', function(err, r) { @@ -101,7 +101,7 @@ exports.shouldCorrectlyThrowTimeoutForReplicationToServersOnInserts = function(t ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false, numberOfRetries:20, retryMiliSeconds:5000}); + var db = new Db('integration_test_', replSet, {w:0, numberOfRetries:20, retryMiliSeconds:5000}); db.open(function(err, p_db) { // Check if we got an error if(err != null) debug("shouldCorrectlyWaitForReplicationToServersOnInserts :: " + inspect(err)); @@ -135,7 +135,7 @@ exports.shouldCorrectlyExecuteSafeFindAndModify = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false, numberOfRetries:20, retryMiliSeconds:5000}); + var db = new Db('integration_test_', replSet, {w:0, numberOfRetries:20, retryMiliSeconds:5000}); db.open(function(err, p_db) { // Check if we got an error if(err != null) debug("shouldWorkCorrectlyWithInserts :: " + inspect(err)); @@ -174,7 +174,7 @@ exports.shouldCorrectlyInsertAfterPrimaryComesBackUp = function(test) { // Insert some data - var db = new Db('integration_test_', replSet, {safe:false, numberOfRetries:20, retryMiliSeconds:5000}); + var db = new Db('integration_test_', replSet, {w:0, numberOfRetries:20, retryMiliSeconds:5000}); // Open db db.open(function(err, p_db) { // Drop collection on replicaset @@ -228,7 +228,7 @@ exports.shouldCorrectlyQueryAfterPrimaryComesBackUp = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false, numberOfRetries:20, retryMiliSeconds:5000}); + var db = new Db('integration_test_', replSet, {w:0, numberOfRetries:20, retryMiliSeconds:5000}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -239,17 +239,21 @@ exports.shouldCorrectlyQueryAfterPrimaryComesBackUp = function(test) { // Open db db.open(function(err, p_db) { + console.log("---------------------------------------------------- 0") // Check if we got an error if(err != null) debug("shouldWorkCorrectlyWithInserts :: " + inspect(err)); // Drop collection on replicaset p_db.dropCollection('shouldCorrectlyQueryAfterPrimaryComesBackUp', function(err, r) { + console.log("---------------------------------------------------- 1") if(err != null) debug("shouldWorkCorrectlyWithInserts :: " + inspect(err)); // Recreate collection on replicaset p_db.createCollection('shouldCorrectlyQueryAfterPrimaryComesBackUp', function(err, collection) { + console.log("---------------------------------------------------- 2") if(err != null) debug("shouldWorkCorrectlyWithInserts :: " + inspect(err)); // Insert a dummy document collection.insert({a:20}, {safe: {w:'majority', wtimeout: 10000}}, function(err, r) { + console.log("---------------------------------------------------- 3") // Kill the primary RS.killPrimary(9, {killNodeWaitTime:0}, function(node) { // Ok let's execute same query a couple of times @@ -285,7 +289,7 @@ exports.shouldWorkCorrectlyWithInserts = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false, numberOfRetries:20, retryMiliSeconds:5000}); + var db = new Db('integration_test_', replSet, {w:0, numberOfRetries:20, retryMiliSeconds:5000}); db.open(function(err, p_db) { if(err != null) debug("shouldWorkCorrectlyWithInserts :: " + inspect(err)); // Drop collection on replicaset @@ -311,7 +315,7 @@ exports.shouldWorkCorrectlyWithInserts = function(test) { test.ok(err == null); - // p_db.collection('shouldWorkCorrectlyWithInserts', {safe:true}, function(err, collection) { + // p_db.collection('shouldWorkCorrectlyWithInserts', {w:1}, function(err, collection) { p_db.collection('shouldWorkCorrectlyWithInserts', function(err, collection) { if(err != null) debug("shouldWorkCorrectlyWithInserts :: " + inspect(err)); // Execute a set of inserts @@ -352,7 +356,7 @@ exports.shouldWorkCorrectlyWithInserts = function(test) { }); // Run second check - collection.save({a:80}, {safe:true}, function(err, r) { + collection.save({a:80}, {w:1}, function(err, r) { if(err != null) debug("shouldWorkCorrectlyWithInserts :: " + inspect(err)); collection.find().toArray(function(err, items) { diff --git a/test/replicaset/map_reduce_test.js b/test/replicaset/map_reduce_test.js index c9e083ebae..0e7d56260e 100644 --- a/test/replicaset/map_reduce_test.js +++ b/test/replicaset/map_reduce_test.js @@ -28,7 +28,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Open the db db.open(function(err, p_db) { // Close connections @@ -100,7 +100,7 @@ exports['Should Correctly group using replicaset'] = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false, slave_ok:true}); + var db = new Db('integration_test_', replSet, {w:0, slave_ok:true}); db.open(function(err, p_db) { if(err != null) debug("shouldGroup :: " + inspect(err)); @@ -142,7 +142,7 @@ exports.shouldPerformMapReduceFunctionInline = function(test) { ); // Establish connection to db - var db = new Db('integration_test_', replSet, {safe:false, slave_ok:true}); + var db = new Db('integration_test_', replSet, {w:0, slave_ok:true}); db.open(function(err, db) { // Parse version of server if available @@ -192,7 +192,7 @@ exports.shouldFailToDoMapReduceToOutCollection = function(test) { ); // Establish connection to db - var db = new Db('integration_test_', replSet, {safe:false, slave_ok:true}); + var db = new Db('integration_test_', replSet, {w:0, slave_ok:true}); db.open(function(err, db) { // Parse version of server if available @@ -243,7 +243,7 @@ exports['Should correctly execute eval'] = function(test) { ); // Establish connection to db - var db = new Db('integration_test_', replSet, {safe:false, slave_ok:true}); + var db = new Db('integration_test_', replSet, {w:0, slave_ok:true}); db.open(function(err, db) { db.eval("1+1", function(err, result) { test.equal(null, err); diff --git a/test/replicaset/query_secondaries_test.js b/test/replicaset/query_secondaries_test.js index c811485fd8..022bfd24b9 100644 --- a/test/replicaset/query_secondaries_test.js +++ b/test/replicaset/query_secondaries_test.js @@ -28,7 +28,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -103,7 +103,7 @@ exports.shouldReadPrimary = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { var waitForSetup = function() { if(Object.keys(p_db.serverConfig._state.secondaries).length == 0) { @@ -134,7 +134,7 @@ exports.shouldCorrectlyTestConnection = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { var waitForSetup = function() { if(Object.keys(p_db.serverConfig._state.secondaries).length == 0) { @@ -170,7 +170,7 @@ exports.shouldCorrectlyQuerySecondaries = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { p_db.createCollection("testsets", {safe:{w:2, wtimeout:10000}}, function(err, collection) { collection.insert([{a:20}, {a:30}, {a:40}], {safe:{w:2, wtimeout:10000}}, function(err, result) { @@ -204,7 +204,7 @@ exports.shouldCorrectlyQueryPrimary = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { if(err != null) debug("shouldReadPrimary :: " + inspect(err)); @@ -230,7 +230,7 @@ exports.shouldAllowToForceReadWithPrimary = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { if(err != null) debug("shouldReadPrimary :: " + inspect(err)); // Create a collection @@ -264,7 +264,7 @@ exports.shouldWorkWithSecondarySeeding = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.on("fullsetup", function() { // Create a collection db.createCollection('shouldWorkWithSecondarySeeding', function(err, collection) { diff --git a/test/replicaset/read_preference_replicaset_test.js b/test/replicaset/read_preference_replicaset_test.js index 10e7318850..e9156818bf 100644 --- a/test/replicaset/read_preference_replicaset_test.js +++ b/test/replicaset/read_preference_replicaset_test.js @@ -29,7 +29,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -71,7 +71,7 @@ var identifyServers = function(rs, dbname, callback) { // Connect to the db and query the state var server = new Server(host, port,{auto_reconnect: true}); // Create db instance - var db = new Db(dbname, server, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(dbname, server, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, db) { numberOfServersToCheck = numberOfServersToCheck - 1; @@ -152,7 +152,7 @@ exports['Connection to replicaset with primary read preference'] = function(test var executedCorrectly = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Trigger test once whole set is up db.on("fullsetup", function() { // Let's get the primary server and wrap the checkout Method to ensure it's the one called for read @@ -196,7 +196,7 @@ exports['Connection to replicaset with secondary read preference with no seconda ); // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Trigger test once whole set is up db.on("fullsetup", function() { // Rip out secondaries forcing an attempt to read from the primary @@ -247,7 +247,7 @@ exports['Connection to replicaset with secondary only read preference no seconda ); // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Trigger test once whole set is up db.on("fullsetup", function() { // Rip out secondaries forcing an attempt to read from the primary @@ -291,7 +291,7 @@ exports['Connection to replicaset with secondary only read preference should ret var executedCorrectly = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Trigger test once whole set is up db.on("fullsetup", function() { // Let's set up all the secondaries @@ -342,7 +342,7 @@ exports['Connection to replicaset with secondary read preference should return s var executedCorrectly = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Trigger test once whole set is up db.on("fullsetup", function() { // Let's set up all the secondaries diff --git a/test/replicaset/read_preferences_all_levels_legacy_test.js b/test/replicaset/read_preferences_all_levels_legacy_test.js index 471de7acad..b1307cc715 100644 --- a/test/replicaset/read_preferences_all_levels_legacy_test.js +++ b/test/replicaset/read_preferences_all_levels_legacy_test.js @@ -29,7 +29,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -71,7 +71,7 @@ var identifyServers = function(rs, dbname, callback) { // Connect to the db and query the state var server = new Server(host, port,{auto_reconnect: true}); // Create db instance - var db = new Db(dbname, server, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(dbname, server, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, db) { numberOfServersToCheck = numberOfServersToCheck - 1; @@ -150,7 +150,7 @@ exports['Set read preference at collection level using collection method'] = fun var executedCorrectlyRead = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, p_db) { // Let's get the primary server and wrap the checkout Method to ensure it's the one called for read @@ -191,7 +191,7 @@ exports['Set read preference at collection level using createCollection method'] var executedCorrectlyRead = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, p_db) { // Let's get the primary server and wrap the checkout Method to ensure it's the one called for read @@ -232,7 +232,7 @@ exports['Set read preference at cursor level'] = function(test) { var executedCorrectlyRead = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, p_db) { // Let's get the primary server and wrap the checkout Method to ensure it's the one called for read @@ -272,7 +272,7 @@ exports['Attempt to change read preference at cursor level after object read'] = var executedCorrectlyRead = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, p_db) { // Let's get the primary server and wrap the checkout Method to ensure it's the one called for read @@ -286,7 +286,7 @@ exports['Attempt to change read preference at cursor level after object read'] = // Grab the collection db.collection("read_preferences_all_levels_2", {}, function(err, collection) { // Insert a bunch of documents - collection.insert([{a:1}, {b:1}, {c:1}], {safe:true}, function(err) { + collection.insert([{a:1}, {b:1}, {c:1}], {w:1}, function(err) { test.equal(null, err); // Set up cursor diff --git a/test/replicaset/read_preferences_all_levels_test.js b/test/replicaset/read_preferences_all_levels_test.js index c3a5d6ce0a..903b79d244 100644 --- a/test/replicaset/read_preferences_all_levels_test.js +++ b/test/replicaset/read_preferences_all_levels_test.js @@ -29,7 +29,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -71,7 +71,7 @@ var identifyServers = function(rs, dbname, callback) { // Connect to the db and query the state var server = new Server(host, port,{auto_reconnect: true}); // Create db instance - var db = new Db(dbname, server, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(dbname, server, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, db) { numberOfServersToCheck = numberOfServersToCheck - 1; @@ -150,7 +150,7 @@ exports['Set read preference at db level'] = function(test) { var executedCorrectlyRead = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null), readPreference:new ReadPreference(ReadPreference.SECONDARY)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null), readPreference:new ReadPreference(ReadPreference.SECONDARY)}); // Connect to the db db.open(function(err, p_db) { // Let's get the primary server and wrap the checkout Method to ensure it's the one called for read @@ -191,7 +191,7 @@ exports['Set read preference at collection level using collection method'] = fun var executedCorrectlyRead = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, p_db) { // Let's get the primary server and wrap the checkout Method to ensure it's the one called for read @@ -232,7 +232,7 @@ exports['Set read preference at collection level using createCollection method'] var executedCorrectlyRead = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, p_db) { // Let's get the primary server and wrap the checkout Method to ensure it's the one called for read @@ -273,7 +273,7 @@ exports['Set read preference at cursor level'] = function(test) { var executedCorrectlyRead = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, p_db) { // Let's get the primary server and wrap the checkout Method to ensure it's the one called for read @@ -313,7 +313,7 @@ exports['Attempt to change read preference at cursor level after object read'] = var executedCorrectlyRead = false; // Create db instance - var db = new Db('integration_test_', replSet, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, p_db) { // Let's get the primary server and wrap the checkout Method to ensure it's the one called for read @@ -327,7 +327,7 @@ exports['Attempt to change read preference at cursor level after object read'] = // Grab the collection db.collection("read_preferences_all_levels_2", {}, function(err, collection) { // Insert a bunch of documents - collection.insert([{a:1}, {b:1}, {c:1}], {safe:true}, function(err) { + collection.insert([{a:1}, {b:1}, {c:1}], {w:1}, function(err) { test.equal(null, err); // Set up cursor diff --git a/test/replicaset/read_preferences_single_test.js b/test/replicaset/read_preferences_single_test.js index 9ebcef523c..8fe65cf734 100644 --- a/test/replicaset/read_preferences_single_test.js +++ b/test/replicaset/read_preferences_single_test.js @@ -29,7 +29,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -71,7 +71,7 @@ var identifyServers = function(rs, dbname, callback) { // Connect to the db and query the state var server = new Server(host, port,{auto_reconnect: true}); // Create db instance - var db = new Db(dbname, server, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db(dbname, server, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); // Connect to the db db.open(function(err, db) { numberOfServersToCheck = numberOfServersToCheck - 1; @@ -145,7 +145,7 @@ exports['Connection to a arbiter host with primary preference should give error' // Connect to the db var server = new Server(host, port,{auto_reconnect: true}); // Create db instance - var db = new Db('integration_test_', server, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', server, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, p_db) { // Grab a collection p_db.createCollection('read_preference_single_test_0', function(err, collection) { @@ -169,7 +169,7 @@ exports['Connection to a single primary host with different read preferences'] = // Connect to the db var server = new Server(host, port,{auto_reconnect: true, readPreference:Server.READ_PRIMARY}); // Create db instance - var db = new Db('integration_test_', server, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', server, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, p_db) { // Grab the collection p_db.collection("read_preference_single_test_0", function(err, collection) { @@ -181,7 +181,7 @@ exports['Connection to a single primary host with different read preferences'] = // Connect to the db var server = new Server(host, port,{auto_reconnect: true, readPreference:Server.READ_SECONDARY}); // Create db instance - var db = new Db('integration_test_', server, {safe:false, slave_ok:true, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', server, {w:0, slave_ok:true, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, p_db) { // Grab the collection db.collection("read_preference_single_test_0", function(err, collection) { @@ -196,7 +196,7 @@ exports['Connection to a single primary host with different read preferences'] = // Connect to the db var server = new Server(host, port,{auto_reconnect: true, readPreference:Server.READ_SECONDARY_ONLY}); // Create db instance - var db = new Db('integration_test_', server, {safe:false, slave_ok:true, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', server, {w:0, slave_ok:true, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, p_db) { // Grab the collection db.collection("read_preference_single_test_0", function(err, collection) { @@ -230,7 +230,7 @@ exports['Connection to a single secondary host with different read preferences'] // Connect to the db var server = new Server(host, port,{auto_reconnect: true, readPreference:Server.READ_PRIMARY}); // Create db instance - var db = new Db('integration_test_', server, {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', server, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, p_db) { // Grab the collection p_db.collection("read_preference_single_test_1", function(err, collection) { @@ -243,7 +243,7 @@ exports['Connection to a single secondary host with different read preferences'] // Connect to the db var server = new Server(host, port,{auto_reconnect: true, readPreference:Server.READ_SECONDARY}); // Create db instance - var db = new Db('integration_test_', server, {safe:false, slave_ok:true, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', server, {w:0, slave_ok:true, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, p_db) { // Grab the collection db.collection("read_preference_single_test_1", function(err, collection) { @@ -256,7 +256,7 @@ exports['Connection to a single secondary host with different read preferences'] // Connect to the db var server = new Server(host, port,{auto_reconnect: true, readPreference:Server.READ_SECONDARY_ONLY}); // Create db instance - var db = new Db('integration_test_', server, {safe:false, slave_ok:true, native_parser: (process.env['TEST_NATIVE'] != null)}); + var db = new Db('integration_test_', server, {w:0, slave_ok:true, native_parser: (process.env['TEST_NATIVE'] != null)}); db.open(function(err, p_db) { // Grab the collection db.collection("read_preference_single_test_1", function(err, collection) { diff --git a/test/replicaset/read_preferences_spec.js b/test/replicaset/read_preferences_spec.js index 9346ac6dd2..cbe9d1bd21 100644 --- a/test/replicaset/read_preferences_spec.js +++ b/test/replicaset/read_preferences_spec.js @@ -30,7 +30,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -63,7 +63,7 @@ var waitForReplicaset = function(callback) { new Server( RS.host, RS.ports[2], { auto_reconnect: true } ) ], {}); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.on("fullsetup", function() { db.close(); callback(); @@ -126,7 +126,7 @@ exports['Should Correctly Checkout Readers'] = function(test) { ); // Open the database - var db = new Db('integration_test_', replSet, {safe:false, recordQueryStats:true}); + var db = new Db('integration_test_', replSet, {w:0, recordQueryStats:true}); // Trigger test once whole set is up db.on("fullsetup", function() { @@ -238,7 +238,7 @@ exports['Should Correctly Use ReadPreference.NEAREST read preference'] = functio ); // Open the database - var db = new Db('integration_test_', replSet, {safe:false, recordQueryStats:true}); + var db = new Db('integration_test_', replSet, {w:0, recordQueryStats:true}); // Trigger test once whole set is up db.on("fullsetup", function() { // Wait for a bit, let ping happen @@ -323,7 +323,7 @@ exports['Should Correctly Use Preferences by tags no strategy'] = function(test) ]); // Open the database - var db = new Db('integration_test_', replSet, {safe:false, recordQueryStats:true}); + var db = new Db('integration_test_', replSet, {w:0, recordQueryStats:true}); // Trigger test once whole set is up db.on("fullsetup", function() { // Wait for a bit, let ping happen @@ -450,7 +450,7 @@ exports['Should Correctly Use ReadPreference.NEAREST read preference with tags'] ); // Open the database - var db = new Db('integration_test_', replSet, {safe:false, recordQueryStats:true}); + var db = new Db('integration_test_', replSet, {w:0, recordQueryStats:true}); // Trigger test once whole set is up db.on("fullsetup", function() { // Wait for a bit, let ping happen @@ -532,7 +532,7 @@ exports['Should Correctly Use ReadPreference.NEAREST read preference with tags a ); // Open the database - var db = new Db('integration_test_', replSet, {safe:false, recordQueryStats:true}); + var db = new Db('integration_test_', replSet, {w:0, recordQueryStats:true}); // Trigger test once whole set is up db.on("fullsetup", function() { // Wait for a bit, let ping happen diff --git a/test/replicaset/reaper_test.js b/test/replicaset/reaper_test.js index ef65da12eb..47e0dfe8cf 100644 --- a/test/replicaset/reaper_test.js +++ b/test/replicaset/reaper_test.js @@ -72,7 +72,7 @@ exports.shouldCorrectlyHandleActiveReaper = function(test) { // Insert some data var db = new Db('integration_test_', replSet, { - safe:false, + w:0, numberOfRetries:20, retryMiliSeconds:5000, reaper:true, diff --git a/test/replicaset/secondary_reads_with_primary_down_test.js b/test/replicaset/secondary_reads_with_primary_down_test.js index 08453afb7a..aaa8c5d104 100644 --- a/test/replicaset/secondary_reads_with_primary_down_test.js +++ b/test/replicaset/secondary_reads_with_primary_down_test.js @@ -28,7 +28,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -110,14 +110,14 @@ exports.shouldCorrectlyReadFromSecondaryEvenIfPrimaryIsDown = function(test) { ensureConnection(test, retries, function(err) { test.ok(err == null); - new Db('integration_test_', replSet, {safe:false}).open(function(err, p_db) { + new Db('integration_test_', replSet, {w:0}).open(function(err, p_db) { test.ok(err == null); test.equal(true, p_db.serverConfig.isConnected()); p_db.createCollection('notempty', function (err, collection) { // Insert a document - collection.insert({a:1}, {safe:true}, function(err, result) { + collection.insert({a:1}, {w:1}, function(err, result) { // Run a simple query collection.findOne(function (err, doc) { diff --git a/test/replicaset/shutdown_test.js b/test/replicaset/shutdown_test.js index 497810c172..308d62ef69 100644 --- a/test/replicaset/shutdown_test.js +++ b/test/replicaset/shutdown_test.js @@ -27,7 +27,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -109,7 +109,7 @@ exports.shouldContinueToQueryWithPrimaryNodeShutdown = function(test) { ensureConnection(test, retries, function(err) { test.ok(err == null); - new Db('integration_test_', replSet, {safe:false}).open(function(err, p_db) { + new Db('integration_test_', replSet, {w:0}).open(function(err, p_db) { test.ok(err == null); test.equal(true, p_db.serverConfig.isConnected()); @@ -151,7 +151,7 @@ exports.shouldContinueToQueryWithSecondaryNodeShutdown = function(test) { ensureConnection(test, retries, function(err) { test.ok(err == null); - new Db('integration_test_', replSet, {safe:false}).open(function(err, p_db) { + new Db('integration_test_', replSet, {w:0}).open(function(err, p_db) { test.ok(err == null); test.equal(true, p_db.serverConfig.isConnected()); diff --git a/test/replicaset/strategies_test.js b/test/replicaset/strategies_test.js index 1f909de089..02e32fb912 100644 --- a/test/replicaset/strategies_test.js +++ b/test/replicaset/strategies_test.js @@ -29,7 +29,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -62,7 +62,7 @@ var waitForReplicaset = function(callback) { new Server( RS.host, RS.ports[2], { auto_reconnect: true } ) ], {}); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.on("fullsetup", function() { db.close(); callback(); @@ -127,7 +127,7 @@ exports['Should Correctly Collect ping information from servers'] = function(tes // Set read preference replSet.setReadPreference({'dc3':'pa', 'dc2':'sf', 'dc1':'ny'}); // Open the database - var db = new Db('integration_test_', replSet, {safe:false, recordQueryStats:true}); + var db = new Db('integration_test_', replSet, {w:0, recordQueryStats:true}); // Trigger test once whole set is up db.on("fullsetup", function() { setTimeout(function() { @@ -163,7 +163,7 @@ exports['Should correctly pick a ping strategy for secondary'] = function(test) // Set read preference replSet.setReadPreference(Server.READ_SECONDARY); // Open the database - var db = new Db('integration_test_', replSet, {safe:false, recordQueryStats:true}); + var db = new Db('integration_test_', replSet, {w:0, recordQueryStats:true}); // Trigger test once whole set is up db.on("fullsetup", function() { db.createCollection('testsets3', function(err, collection) { @@ -204,7 +204,7 @@ exports['Should correctly pick a statistics strategy for secondary'] = function( // Set read preference replSet.setReadPreference(Server.READ_SECONDARY); // Open the database - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Trigger test once whole set is up db.on("fullsetup", function() { db.createCollection('testsets2', function(err, collection) { @@ -260,7 +260,7 @@ exports['Should correctly create and start a ping strategy'] = function(test) { replSet.setReadPreference(Server.READ_SECONDARY); // Open the database - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Trigger test once whole set is up db.on("fullsetup", function() { diff --git a/test/replicaset/tags_test.js b/test/replicaset/tags_test.js index 1634fdf057..53a68d46df 100644 --- a/test/replicaset/tags_test.js +++ b/test/replicaset/tags_test.js @@ -29,7 +29,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Print any errors db.on("error", function(err) { console.log("============================= ensureConnection caught error") @@ -62,7 +62,7 @@ var waitForReplicaset = function(callback) { new Server( RS.host, RS.ports[2], { auto_reconnect: true } ) ], {}); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.on("fullsetup", function() { db.close(); callback(); @@ -124,7 +124,7 @@ exports['Should Correctly Connect With Default Replicaset And Insert Document Fo {} ); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Trigger test once whole set is up db.on("fullsetup", function() { // Recreate collection on replicaset @@ -164,7 +164,7 @@ exports['Should Honor setReadPreference primary'] = function(test) { // Set read preference replSet.setReadPreference(Server.READ_PRIMARY); // Open the database - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Trigger test once whole set is up db.on("fullsetup", function() { // Checkout a reader and make sure it's the primary @@ -200,7 +200,7 @@ exports['Should Honor setReadPreference secondary'] = function(test) { // Set read preference replSet.setReadPreference(Server.READ_SECONDARY); // Open the database - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); // Trigger test once whole set is up db.on("fullsetup", function() { // Checkout a reader and make sure it's the primary diff --git a/test/replicaset/two_server_tests.js b/test/replicaset/two_server_tests.js index 988a1175fd..07ac5ab952 100644 --- a/test/replicaset/two_server_tests.js +++ b/test/replicaset/two_server_tests.js @@ -28,7 +28,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { db.close(); if(err != null) { @@ -50,7 +50,7 @@ var waitForReplicaset = function(callback) { new Server( RS.host, RS.ports[0], { auto_reconnect: true } ), ], {}); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.on("fullsetup", function() { db.close(); callback(); @@ -116,7 +116,7 @@ exports.shouldCorrectlyExecuteSafeFindAndModify = function(test) { ); // Insert some data - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { if(err != null) debug("shouldWorkCorrectlyWithInserts :: " + inspect(err)); db = p_db; diff --git a/test/replicaset/url_connection_test.js b/test/replicaset/url_connection_test.js index 4b94066e65..8aa6ad7249 100644 --- a/test/replicaset/url_connection_test.js +++ b/test/replicaset/url_connection_test.js @@ -29,7 +29,7 @@ var ensureConnection = function(test, numberOfTries, callback) { if(numberOfTries <= 0) return callback(new Error("could not connect correctly"), null); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.open(function(err, p_db) { db.close(); if(err != null) { @@ -51,7 +51,7 @@ var waitForReplicaset = function(callback) { new Server( RS.host, RS.ports[0], { auto_reconnect: true } ), ], {}); - var db = new Db('integration_test_', replSet, {safe:false}); + var db = new Db('integration_test_', replSet, {w:0}); db.on("fullsetup", function() { db.close(); callback(); diff --git a/test/sharded/operations_test.js b/test/sharded/operations_test.js index 3d3518373e..98e6b2bdb2 100644 --- a/test/sharded/operations_test.js +++ b/test/sharded/operations_test.js @@ -76,7 +76,7 @@ exports.shouldCorrectlyPerformAllOperationsAgainstShardedSystem = function(test) } // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.open(function(err, db) { test.equal(null, err); test.ok(db != null); @@ -86,7 +86,7 @@ exports.shouldCorrectlyPerformAllOperationsAgainstShardedSystem = function(test) test.equal(null, err); // Perform an update - collection.update({a:0}, {$set: {c:1}}, {safe:true}, function(err, result) { + collection.update({a:0}, {$set: {c:1}}, {w:1}, function(err, result) { test.equal(null, err); var numberOfRecords = 0; diff --git a/test/sharded/partial_read_test.js b/test/sharded/partial_read_test.js index f9b80807b0..014767473b 100644 --- a/test/sharded/partial_read_test.js +++ b/test/sharded/partial_read_test.js @@ -86,7 +86,7 @@ exports.shouldCorrectlyPerformAllOperationsAgainstShardedSystem = function(test) } // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.open(function(err, db) { test.equal(null, err); test.ok(db != null); diff --git a/test/sharded/read_preferences_sharded_test.js b/test/sharded/read_preferences_sharded_test.js index cfa5ea425a..95df5d24e7 100644 --- a/test/sharded/read_preferences_sharded_test.js +++ b/test/sharded/read_preferences_sharded_test.js @@ -74,7 +74,7 @@ exports['Should correctly perform a Mongos secondary read using the read prefere ]) // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.open(function(err, db) { test.equal(null, err); test.ok(db != null); @@ -119,7 +119,7 @@ exports['Should correctly fail a Mongos read using a unsupported read preference ]) // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.open(function(err, db) { test.equal(null, err); test.ok(db != null); @@ -162,7 +162,7 @@ exports['Should fail a Mongos secondary read using the read preference and tags ]) // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.open(function(err, db) { test.equal(null, err); test.ok(db != null); @@ -205,7 +205,7 @@ exports['Should correctly read from a tagged secondary using Mongos'] = function ]) // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.open(function(err, db) { test.equal(null, err); test.ok(db != null); @@ -250,7 +250,7 @@ exports['Should correctly perform gridstore read and write'] = function(test) { ]) // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.open(function(err, db) { test.equal(null, err); test.ok(db != null); @@ -277,7 +277,7 @@ exports['Should correctly perform gridstore read and write'] = function(test) { exports['Should correctly connect to MongoS using single server instance'] = function(test) { var mongos = new Server("localhost", 50000, { auto_reconnect: true }); // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.open(function(err, db) { test.equal(null, err); test.ok(db != null); diff --git a/test/sharded/simple_sharded_setup_test.js b/test/sharded/simple_sharded_setup_test.js index a989d87c72..cc4a3c8a2e 100644 --- a/test/sharded/simple_sharded_setup_test.js +++ b/test/sharded/simple_sharded_setup_test.js @@ -71,7 +71,7 @@ exports.shouldCorrectlyConnectToMongoSShardedSetup = function(test) { ]) // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.open(function(err, db) { test.equal(null, err); test.ok(db != null); @@ -79,7 +79,7 @@ exports.shouldCorrectlyConnectToMongoSShardedSetup = function(test) { // Perform a simple insert into a collection var collection = db.collection("shard_test"); // Insert a simple doc - collection.insert({test:1}, {safe:true}, function(err, result) { + collection.insert({test:1}, {w:1}, function(err, result) { test.equal(null, err); collection.findOne({test:1}, {}, {readPreference:new ReadPreference(ReadPreference.SECONDARY)}, function(err, item) { @@ -106,7 +106,7 @@ exports.shouldCorrectlyEmitOpenEvent = function(test) { var openCalled = false; // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.once("open", function(_err, _db) { openCalled = true; }) @@ -132,7 +132,7 @@ exports.shouldCorrectlyConnectToMongoSShardedSetupAndKillTheMongoSProxy = functi ], {ha:true}) // Connect using the mongos connections - var db = new Db('integration_test_', mongos, {safe:false}); + var db = new Db('integration_test_', mongos, {w:0}); db.open(function(err, db) { test.equal(null, err); test.ok(db != null); @@ -140,14 +140,14 @@ exports.shouldCorrectlyConnectToMongoSShardedSetupAndKillTheMongoSProxy = functi // Perform a simple insert into a collection var collection = db.collection("shard_test2"); // Insert a simple doc - collection.insert({test:1}, {safe:true}, function(err, result) { + collection.insert({test:1}, {w:1}, function(err, result) { test.equal(null, err); // Kill the mongos proxy Shard.killMongoS(50000, function(err, result) { // Attempt another insert - collection.insert({test:2}, {safe:true}, function(err, result) { + collection.insert({test:2}, {w:1}, function(err, result) { test.equal(null, err); test.equal(1, db.serverConfig.downServers.length); @@ -161,7 +161,7 @@ exports.shouldCorrectlyConnectToMongoSShardedSetupAndKillTheMongoSProxy = functi // Kill the mongos proxy Shard.killMongoS(50001, function(err, result) { // Attempt another insert - collection.insert({test:3}, {safe:true}, function(err, result) { + collection.insert({test:3}, {w:1}, function(err, result) { test.equal(null, err); test.equal(1, db.serverConfig.downServers.length); @@ -172,7 +172,7 @@ exports.shouldCorrectlyConnectToMongoSShardedSetupAndKillTheMongoSProxy = functi // Kill the mongos proxy Shard.killMongoS(50000, function(err, result) { // Attempt another insert - collection.insert({test:4}, {safe:true}, function(err, result) { + collection.insert({test:4}, {w:1}, function(err, result) { test.equal(null, err); // Wait for the ha process to pick up the existing new server diff --git a/test/streaming_test.js b/test/streaming_test.js index 5981316995..1fb7796b16 100644 --- a/test/streaming_test.js +++ b/test/streaming_test.js @@ -23,7 +23,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -53,7 +53,7 @@ exports.tearDown = function(callback) { exports.shouldStreamRecordsCallsDataTheRightNumberOfTimes = function(test) { client.createCollection('test_stream_records', function(err, collection) { test.ok(collection instanceof Collection); - collection.insert([{'a':1}, {'b' : 2}, {'c' : 3}, {'d' : 4}, {'e' : 5}], {safe:true}, function(err, ids) { + collection.insert([{'a':1}, {'b' : 2}, {'c' : 3}, {'d' : 4}, {'e' : 5}], {w:1}, function(err, ids) { var stream = collection.find({}, {'limit' : 3}).streamRecords(); var callsToEnd = 0; stream.on('end', function() { @@ -72,7 +72,7 @@ exports.shouldStreamRecordsCallsDataTheRightNumberOfTimes = function(test) { exports.shouldStreamRecordsCallsEndTheRightNumberOfTimes = function(test) { client.createCollection('test_stream_records', function(err, collection) { test.ok(collection instanceof Collection); - collection.insert([{'a':1}, {'b' : 2}, {'c' : 3}, {'d' : 4}, {'e' : 5}], {safe:true}, function(err, ids) { + collection.insert([{'a':1}, {'b' : 2}, {'c' : 3}, {'d' : 4}, {'e' : 5}], {w:1}, function(err, ids) { var cursor = collection.find({}, {'limit' : 3}); var stream = cursor.streamRecords(function(er,item) {}); var callsToEnd = 0; @@ -102,7 +102,7 @@ exports.shouldStreamDocumentsWithLimitForFetching = function(test) { client.createCollection('test_streaming_function_with_limit_for_fetching', function(err, collection) { test.ok(collection instanceof Collection); - collection.insert(docs, {safe:true}, function(err, ids) { + collection.insert(docs, {w:1}, function(err, ids) { var cursor = collection.find({}); // Execute find on all the documents var stream = cursor.streamRecords({fetchSize:1000}); diff --git a/test/tools/replica_set_manager.js b/test/tools/replica_set_manager.js index cf58a0d0e6..a8a5c5eff5 100644 --- a/test/tools/replica_set_manager.js +++ b/test/tools/replica_set_manager.js @@ -540,7 +540,7 @@ ReplicaSetManager.prototype.getConnection = function(node, callback) { // Get the node if(self.mongods[node] != null) { var intervalId = setInterval(function() { - var connection = new Db("replicaset_test", new Server(self.host, self.mongods[node]["port"], {ssl:self.ssl, poolSize:1}), {safe:false}); + var connection = new Db("replicaset_test", new Server(self.host, self.mongods[node]["port"], {ssl:self.ssl, poolSize:1}), {w:0}); connection.open(function(err, db) { if(err == null && !done) { // Set done diff --git a/test/tools/sharded_manager.js b/test/tools/sharded_manager.js index 6d6942c2a6..788477b07f 100644 --- a/test/tools/sharded_manager.js +++ b/test/tools/sharded_manager.js @@ -177,7 +177,7 @@ ShardedManager.prototype.restartMongoS = function(port, callback) { ShardedManager.prototype.shardDb = function(dbname, callback) { if(this.mongosProxies.length == 0) throw new Error("need at least one mongos server"); // Set up the db connection - var db = new Db("admin", new Server("localhost", this.mongosRangeSet, {auto_reconnect: true, poolSize: 4}), {safe:false}); + var db = new Db("admin", new Server("localhost", this.mongosRangeSet, {auto_reconnect: true, poolSize: 4}), {w:0}); db.open(function(err, db) { // Run the add shard commands db.command({enablesharding:dbname}, function(err, result) { @@ -191,7 +191,7 @@ ShardedManager.prototype.shardDb = function(dbname, callback) { ShardedManager.prototype.shardCollection = function(collectionName, key, callback) { if(this.mongosProxies.length == 0) throw new Error("need at least one mongos server"); // Set up the db connection - var db = new Db("admin", new Server("localhost", this.mongosRangeSet, {auto_reconnect: true, poolSize: 4}), {safe:false}); + var db = new Db("admin", new Server("localhost", this.mongosRangeSet, {auto_reconnect: true, poolSize: 4}), {w:0}); db.open(function(err, db) { // Run the add shard commands db.command({shardcollection:collectionName, key:key}, function(err, result) { @@ -204,7 +204,7 @@ ShardedManager.prototype.shardCollection = function(collectionName, key, callbac var setupShards = function(self, callback) { if(self.mongosProxies.length == 0) throw new Error("need at least one mongos server"); // Set up the db connection - var db = new Db("admin", new Server("localhost", self.mongosRangeSet, {auto_reconnect: true, poolSize: 4}), {safe:false}); + var db = new Db("admin", new Server("localhost", self.mongosRangeSet, {auto_reconnect: true, poolSize: 4}), {w:0}); db.open(function(err, db) { // console.log("=================================================================") // console.dir(err) diff --git a/test/unicode_test.js b/test/unicode_test.js index 34c992fdd3..f347cb89d3 100644 --- a/test/unicode_test.js +++ b/test/unicode_test.js @@ -22,7 +22,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db @@ -94,7 +94,7 @@ exports.shouldCorrectlySaveUnicodeContainingDocument = function(test) { client.createCollection('test_should_correctly_save_unicode_containing_document', function(err, collection) { doc['_id'] = 'felixge'; - collection.save(doc, {safe:true}, function(err, doc) { + collection.save(doc, {w:1}, function(err, doc) { collection.findOne(function(err, doc) { test.equal('felixge', doc._id); test.done(); @@ -107,9 +107,9 @@ exports.shouldCorrectlySaveUnicodeContainingDocument = function(test) { exports.shouldCorrectlyInsertUnicodeCharacters = function(test) { client.createCollection('unicode_test_collection', function(err, collection) { var test_strings = ["ouooueauiOUOOUEAUI", "öüóőúéáűíÖÜÓŐÚÉÁŰÍ", "本荘由利地域に洪水警報"]; - collection.insert({id: 0, text: test_strings[0]}, {safe:true}, function(err, ids) { - collection.insert({id: 1, text: test_strings[1]}, {safe:true}, function(err, ids) { - collection.insert({id: 2, text: test_strings[2]}, {safe:true}, function(err, ids) { + collection.insert({id: 0, text: test_strings[0]}, {w:1}, function(err, ids) { + collection.insert({id: 1, text: test_strings[1]}, {w:1}, function(err, ids) { + collection.insert({id: 2, text: test_strings[2]}, {w:1}, function(err, ids) { collection.find().each(function(err, item) { if(item != null) { test.equal(test_strings[item.id], item.text); @@ -129,7 +129,7 @@ exports.shouldCreateObjectWithChineseObjectName = function(test) { client.createCollection('create_object_with_chinese_object_name', function(err, r) { client.collection('create_object_with_chinese_object_name', function(err, collection) { - collection.insert(object, {safe:true}, function(err, result) { + collection.insert(object, {w:1}, function(err, result) { collection.findOne(function(err, item) { test.equal(object['客家话'], item['客家话']) @@ -145,7 +145,7 @@ exports.shouldCreateObjectWithChineseObjectName = function(test) { exports.shouldCorrectlyHandleUT8KeyNames = function(test) { client.createCollection('test_utf8_key_name', function(err, collection) { - collection.insert({'šđžčćŠĐŽČĆ':1}, {safe:true}, function(err, ids) { + collection.insert({'šđžčćŠĐŽČĆ':1}, {w:1}, function(err, ids) { // finished_test({test_utf8_key_name:'ok'}); collection.find({}, {'fields': ['šđžčćŠĐŽČĆ']}).toArray(function(err, items) { test.equal(1, items[0]['šđžčćŠĐŽČĆ']); diff --git a/test/write_preferences_test.js b/test/write_preferences_test.js index b655d0afb7..8cd2eef09b 100644 --- a/test/write_preferences_test.js +++ b/test/write_preferences_test.js @@ -23,7 +23,7 @@ var client = null; */ exports.setUp = function(callback) { var self = exports; - client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {safe:false, native_parser: (process.env['TEST_NATIVE'] != null)}); + client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize: 4, ssl:useSSL}), {w:0, native_parser: (process.env['TEST_NATIVE'] != null)}); client.open(function(err, db_p) { if(numberOfTestsRun == (Object.keys(self).length)) { // If first test drop the db