From 2a2ad24e9a9463e82629c31f351c31e7ed4c70a5 Mon Sep 17 00:00:00 2001 From: Joseba Legarreta Date: Tue, 22 Aug 2017 11:50:28 +0200 Subject: [PATCH 01/16] Return 0 if there are no documents to sum --- lib/private/machines/sum-records.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/sum-records.js b/lib/private/machines/sum-records.js index 6bd07c18a..503e01ca8 100644 --- a/lib/private/machines/sum-records.js +++ b/lib/private/machines/sum-records.js @@ -77,7 +77,7 @@ module.exports = { ], function aggregateCb(err, nativeResult) { if (err) { return exits.error(err); } - var sum = null; + var sum = 0; if (_.first(nativeResult)) { sum = _.first(nativeResult).sum; } return exits.success(sum); });// From 40f5e09a414ea8232784b5b53f896ae56d65d8b9 Mon Sep 17 00:00:00 2001 From: Joseba Legarreta Date: Sun, 29 Mar 2020 12:29:58 +0200 Subject: [PATCH 02/16] update mongo driver and support +srv protocol --- lib/private/normalize-datastore-config/index.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/normalize-datastore-config/index.js b/lib/private/normalize-datastore-config/index.js index 9db9f44d2..f42b0665f 100644 --- a/lib/private/normalize-datastore-config/index.js +++ b/lib/private/normalize-datastore-config/index.js @@ -322,7 +322,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // If relevant, validate that the RIGHT protocol was found. if (expectedProtocolPrefix) { - if (parsedConnectionStr.protocol !== expectedProtocolPrefix+':') { + if (parsedConnectionStr.protocol !== expectedProtocolPrefix+':' && parsedConnectionStr.protocol !== expectedProtocolPrefix+'+srv:') { throw flaverr('E_BAD_CONFIG', new Error( 'Provided URL ('+util.inspect(dsConfig.url,{depth:5})+') has an invalid protocol.\n'+ 'If included, the protocol must be "'+expectedProtocolPrefix+'://".\n'+ diff --git a/package.json b/package.json index 154af2537..47dfa753b 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "async": "2.0.1", "flaverr": "1.1.1", "machine": "^15.0.0", - "mongodb": "2.2.25", + "mongodb": "3.5.5", "qs": "6.4.0" }, "devDependencies": { From 6b645b8c3d3e9dc04d2091455518a6e400ab9e0e Mon Sep 17 00:00:00 2001 From: Joseba Legarreta Date: Sun, 29 Mar 2020 12:36:03 +0200 Subject: [PATCH 03/16] Update manager client connection --- lib/private/machines/create-manager.js | 10 ++++++++-- lib/private/machines/destroy-manager.js | 4 ++-- lib/private/machines/release-connection.js | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index 8f5547abf..f7ba34f7e 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -125,14 +125,20 @@ module.exports = { var mongoUrl = _clientConfig.url; _clientConfig = _.omit(_clientConfig, ['url', 'user', 'password', 'host', 'port', 'database']); - NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig, function connectCb(err, db) { + _clientConfig = Object.assign({ + useNewUrlParser: true, + useUnifiedTopology: true + }, _clientConfig); + + NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig, function connectCb(err, client) { if (err) { return exits.error(err); } // `db` will be our manager. // (This variable is just for clarity.) - var manager = db; + var manager = client.db(_clientConfig.database); + manager.client = client; // Now mutate this manager, giving it a telltale. // diff --git a/lib/private/machines/destroy-manager.js b/lib/private/machines/destroy-manager.js index c7e315a18..4643dd5dc 100644 --- a/lib/private/machines/destroy-manager.js +++ b/lib/private/machines/destroy-manager.js @@ -69,12 +69,12 @@ module.exports = { // If the manager doesn't have a `close` function for some reason, // then catch that ahead of time so we can provide a slightly nicer // error message and help prevent confusion. - if (!_.isObject(inputs.manager) || !_.isFunction(inputs.manager.close)) { + if (!_.isObject(inputs.manager.client) || !_.isFunction(inputs.manager.client.close)) { return exits.error(new Error('The provided `manager` is not a valid manager created by this driver. (It should be a dictionary which contains a `close` function, at the very least.)')); } // Call close on the manager - inputs.manager.close(); + inputs.manager.client.close(); return exits.success({ meta: inputs.meta diff --git a/lib/private/machines/release-connection.js b/lib/private/machines/release-connection.js index 3a5d8690c..d7d18f0a0 100644 --- a/lib/private/machines/release-connection.js +++ b/lib/private/machines/release-connection.js @@ -67,7 +67,7 @@ module.exports = { // If the connection doesn't have a `close` function for some reason, // then catch that ahead of time so we can provide a slightly nicer // error message and help prevent confusion. - if (!_.isObject(inputs.connection) || !_.isFunction(inputs.connection.close)) { + if (!_.isObject(inputs.connection.client) || !_.isFunction(inputs.connection.client.close)) { return exits.badConnection(); } From e96ad1c3633f4e82a23358b644a45f320eef63cb Mon Sep 17 00:00:00 2001 From: Joseba Legarreta Date: Sun, 29 Mar 2020 12:39:12 +0200 Subject: [PATCH 04/16] Update package version to 1.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47dfa753b..6c0e712fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sails-mongo", - "version": "1.1.0", + "version": "1.2.0", "description": "Mongo DB adapter for Sails.js/Waterline.", "main": "./lib", "scripts": { From d9068bcef5d547f2c61b3f5c207564046e93bc71 Mon Sep 17 00:00:00 2001 From: Joseba Legarreta Date: Sun, 29 Mar 2020 14:12:43 +0200 Subject: [PATCH 05/16] Add 'retryWrites' to whitelist constants --- lib/private/constants/config-whitelist.constant.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/constants/config-whitelist.constant.js b/lib/private/constants/config-whitelist.constant.js index aa0379d05..4cc8c2f57 100644 --- a/lib/private/constants/config-whitelist.constant.js +++ b/lib/private/constants/config-whitelist.constant.js @@ -12,7 +12,7 @@ module.exports = [ // Connection Options: 'poolSize', 'autoReconnect', 'noDelay', 'keepAlive', 'connectTimeoutMS', - 'socketTimeoutMS', 'reconnectTries', 'reconnectInterval', + 'socketTimeoutMS', 'reconnectTries', 'reconnectInterval', 'retryWrites', // Other Options: 'ha', 'haInterval', 'replicaSet', 'secondaryAcceptableLatencyMS', From 167a5a9cd07805b91e009b629f9d063c57341a2e Mon Sep 17 00:00:00 2001 From: Joseba Legarreta Date: Mon, 30 Mar 2020 13:04:44 +0200 Subject: [PATCH 06/16] Update collection.insert with .insertOne or .insertMany, avoiding deprecation warning --- test/run-adapter-specific-tests.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index c9ba5c6fb..aeb8ba8e4 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -145,7 +145,7 @@ describe('dontUseObjectIds', function() { describe('Updating a single record', function() { it('should update the record correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insert({_id: 123, name: 'bob'}, function(err) { + models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}, function(err) { if (err) {return done(err);} models.user.update({id: 123}, {name: 'joe'}).exec(function(err, records) { if (err) {return done(err);} @@ -164,7 +164,7 @@ describe('dontUseObjectIds', function() { it('should update the records correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insert([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}], function(err) { + models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}], function(err) { if (err) {return done(err);} models.user.update({id: {'>': 0}}, {name: 'joe'}).exec(function(err, records) { if (err) {return done(err);} @@ -185,7 +185,7 @@ describe('dontUseObjectIds', function() { it('should find a record w/ a numeric ID', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insert({_id: 123, name: 'bob'}, function(err) { + models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}, function(err) { if (err) {return done(err);} models.user.findOne({id: 123}).exec(function(err, record) { if (err) {return done(err);} @@ -203,7 +203,7 @@ describe('dontUseObjectIds', function() { it('should find the records correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insert([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}], function(err) { + models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}], function(err) { if (err) {return done(err);} models.user.find({id: {'>': 0}}).exec(function(err, records) { if (err) {return done(err);} @@ -222,7 +222,7 @@ describe('dontUseObjectIds', function() { describe('Deleting a single record', function() { it('should delete the record correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insert({_id: 123, name: 'bob'}, function(err) { + models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}, function(err) { if (err) {return done(err);} models.user.destroy({id: 123}).exec(function(err) { if (err) {return done(err);} @@ -244,7 +244,7 @@ describe('dontUseObjectIds', function() { it('should delete the records correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insert([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}], function(err) { + models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}], function(err) { if (err) {return done(err);} models.user.destroy({id: {'>': 0}}).exec(function(err) { if (err) {return done(err);} From 059737f14fbdb5f643329a0068eaac8118f98b38 Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sun, 28 Jun 2020 21:22:51 -0500 Subject: [PATCH 07/16] Updated options whitelist constants based on current MongoDB 3.5 options --- .../constants/config-whitelist.constant.js | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/private/constants/config-whitelist.constant.js b/lib/private/constants/config-whitelist.constant.js index 4cc8c2f57..207806ac2 100644 --- a/lib/private/constants/config-whitelist.constant.js +++ b/lib/private/constants/config-whitelist.constant.js @@ -1,24 +1,34 @@ // CONFIG_WHITELIST // // The set of non-standard property names in configuration to consider valid. -// Leave `undefined` to tolerate almost anything-- or set to an empty array to +// Leave 'undefined' to tolerate almost anything-- or set to an empty array to // prevent everything except standard properties. // -// > http://mongodb.github.io/node-mongodb-native/2.2/reference/connecting/connection-settings/ +// > https://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html#.connect module.exports = [ // SSL Options: - 'ssl', 'sslValidate', 'sslCA', 'sslCert', 'sslKey', 'sslPass', + 'ssl', 'sslValidate', 'sslCA', 'sslCert', 'sslKey', 'sslPass', 'sslCRL', 'checkServerIdentity', + + // TLS Options: + 'tls', 'tlsInsecure', 'tlsCAFile', 'tlsCertificateKeyFile', 'tlsCertificateKeyFilePassword', + 'tlsAllowInvalidCertificates', 'tlsAllowInvalidHostnames', // Connection Options: - 'poolSize', 'autoReconnect', 'noDelay', 'keepAlive', 'connectTimeoutMS', - 'socketTimeoutMS', 'reconnectTries', 'reconnectInterval', 'retryWrites', + 'poolSize', 'autoReconnect', 'noDelay', 'keepAlive', 'keepAliveInitialDelay', 'connectTimeoutMS', + 'socketTimeoutMS', 'family', 'reconnectTries', 'reconnectInterval', // Other Options: 'ha', 'haInterval', 'replicaSet', 'secondaryAcceptableLatencyMS', 'acceptableLatencyMS', 'connectWithNoPrimary', 'authSource', 'w', 'wtimeout', 'j', 'forceServerObjectId', 'serializeFunctions', - 'ignoreUndefined', 'raw', 'promoteLongs', 'bufferMaxEntries', - 'readPreference', 'pkFactory', 'readConcern', 'appname' + 'ignoreUndefined', 'raw', 'bufferMaxEntries', 'readPreference', + 'pkFactory', 'promiseLibrary', 'readConcern', 'maxStalenessSeconds', + 'loggerLevel', 'logger', 'promoteValues', 'promoteLongs', 'promoteBuffers', + 'domainsEnabled', 'validateOptions', 'appname', 'auth.user', 'auth.password', + 'authMechanism', 'compression', 'fsync', 'readPreferenceTags', 'numberOfRetries', + 'auto_reconnect', 'monitorCommands', 'minSize', 'useNewUrlParser', 'useUnifiedTopology', + 'localThresholdMS', 'serverSelectionTimeoutMS', 'heartbeatFrequencyMS', 'autoEncryption', + 'driverInfo' ]; From 805b5b6907890086c672334ba19e2874d09d79fc Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sun, 28 Jun 2020 21:23:18 -0500 Subject: [PATCH 08/16] Make use of updateOne --- test/run-adapter-specific-tests.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index aeb8ba8e4..557fb7d33 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -147,10 +147,10 @@ describe('dontUseObjectIds', function() { it('should update the record correctly', function(done) { models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}, function(err) { if (err) {return done(err);} - models.user.update({id: 123}, {name: 'joe'}).exec(function(err, records) { + models.user.updateOne({id: 123}, {name: 'joe'}).exec(function(err, record) { if (err) {return done(err);} - assert.equal(records[0].id, 123); - assert.equal(records[0].name, 'joe'); + assert.equal(record.id, 123); + assert.equal(record.name, 'joe'); return done(); }); From cacdb529d2994255947f5a5d43a78530ee0ab74a Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sun, 28 Jun 2020 21:23:39 -0500 Subject: [PATCH 09/16] Add test for client existence on create manager test --- test/connectable/create-manager.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/connectable/create-manager.test.js b/test/connectable/create-manager.test.js index 617369b77..c3ecfe5a6 100644 --- a/test/connectable/create-manager.test.js +++ b/test/connectable/create-manager.test.js @@ -1,5 +1,6 @@ var assert = require('assert'); var createManager = require('machine').build(require('../../').createManager); +var MongoClient = require('mongodb').MongoClient; describe('Connectable ::', function() { describe('Create Manager', function() { @@ -43,6 +44,7 @@ describe('Connectable ::', function() { try { assert(report.manager); + assert(report.manager.client instanceof MongoClient ); } catch (e) { return done(e); } return done(); From 36d815702cbac87e1a53039d63ead4934afd1df2 Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sun, 28 Jun 2020 21:24:56 -0500 Subject: [PATCH 10/16] Remove .jshint --- .jshintrc | 134 ------------------------------------------------------ 1 file changed, 134 deletions(-) delete mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 5099273dd..000000000 --- a/.jshintrc +++ /dev/null @@ -1,134 +0,0 @@ -{ - // ┬┌─┐╦ ╦╦╔╗╔╔╦╗┬─┐┌─┐ - // │└─┐╠═╣║║║║ ║ ├┬┘│ - // o└┘└─┘╩ ╩╩╝╚╝ ╩ ┴└─└─┘ - // - // This file (`.jshintrc`) exists to help with consistency of code - // throughout this package, and throughout Sails and the Node-Machine project. - // - // To review what each of these options mean, see: - // http://jshint.com/docs/options - // - // (or: https://github.com/jshint/jshint/blob/master/examples/.jshintrc) - - - - ////////////////////////////////////////////////////////////////////// - // NOT SUPPORTED IN SOME JSHINT VERSIONS SO LEAVING COMMENTED OUT: - ////////////////////////////////////////////////////////////////////// - // Prevent overwriting prototypes of native classes like `Array`. - // (doing this is _never_ ok in any of our packages that are intended - // to be used as dependencies of other developers' modules and apps) - // "freeze": true, - ////////////////////////////////////////////////////////////////////// - - - ////////////////////////////////////////////////////////////////////// - // EVERYTHING ELSE: - ////////////////////////////////////////////////////////////////////// - - // Allow the use of ES6 features. - // (re ES7, see https://github.com/jshint/jshint/issues/2297) - "esversion": 6, - - // Allow the use of `eval` and `new Function()` - // (we sometimes actually need to use these things) - "evil": true, - - // Tolerate funny-looking dashes in RegExp literals. - // (see https://github.com/jshint/jshint/issues/159#issue-903547) - "regexdash": true, - - // The potential runtime "Environments" (as defined by jshint) - // that the _style_ of code written in this package should be - // compatible with (not the code itself, of course). - "browser": true, - "node": true, - "wsh": true, - - // Tolerate the use `[]` notation when dot notation would be possible. - // (this is sometimes preferable for readability) - "sub": true, - - // Do NOT suppress warnings about mixed tabs and spaces - // (two spaces always, please; see `.editorconfig`) - "smarttabs": false, - - // Suppress warnings about trailing whitespace - // (this is already enforced by the .editorconfig, so no need to warn as well) - "trailing": false, - - // Suppress warnings about the use of expressions where fn calls or assignments - // are expected, and about using assignments where conditionals are expected. - // (while generally a good idea, without this setting, JSHint needlessly lights up warnings - // in existing, working code that really shouldn't be tampered with. Pandora's box and all.) - "expr": true, - "boss": true, - - // Do NOT suppress warnings about using functions inside loops - // (in the general case, we should be using iteratee functions with `_.each()` - // or `Array.prototype.forEach()` instead of `for` or `while` statements - // anyway. This warning serves as a helpful reminder.) - "loopfunc": false, - - // Suppress warnings about "weird constructions" - // i.e. allow code like: - // ``` - // (new (function OneTimeUsePrototype () { } )) - // ``` - // - // (sometimes order of operations in JavaScript can be scary. There is - // nothing wrong with using an extra set of parantheses when the mood - // strikes or you get "that special feeling".) - "supernew": true, - - // Do NOT allow backwards, node-dependency-style commas. - // (while this code style choice was used by the project in the past, - // we have since standardized these practices to make code easier to - // read, albeit a bit less exciting) - "laxcomma": false, - - // Do NOT allow avant garde use of commas in conditional statements. - // (this prevents accidentally writing code like: - // ``` - // if (!_.contains(['+ci', '-ci', '∆ci', '+ce', '-ce', '∆ce']), change.verb) {...} - // ``` - // See the problem in that code? Neither did we-- that's the problem!) - "nocomma": true, - - // Strictly enforce the consistent use of single quotes. - // (this is a convention that was established primarily to make it easier - // to grep [or FIND+REPLACE in Sublime] particular string literals in - // JavaScript [.js] files. Note that JSON [.json] files are, of course, - // still written exclusively using double quotes around key names and - // around string literals.) - "quotmark": "single", - - // Do NOT suppress warnings about the use of `==null` comparisons. - // (please be explicit-- use Lodash or `require('util')` and call - // either `.isNull()` or `.isUndefined()`) - "eqnull": false, - - // Strictly enforce the use of curly braces with `if`, `else`, and `switch` - // as well as, much less commonly, `for` and `while` statements. - // (this is just so that all of our code is consistent, and to avoid bugs) - "curly": true, - - // Strictly enforce the use of `===` and `!==`. - // (this is always a good idea. Check out "Truth, Equality, and JavaScript" - // by Angus Croll [the author of "If Hemmingway Wrote JavaScript"] for more - // explanation as to why.) - "eqeqeq": true, - - // Allow initializing variables to `undefined`. - // For more information, see: - // • https://jslinterrors.com/it-is-not-necessary-to-initialize-a-to-undefined - // • https://github.com/jshint/jshint/issues/1484 - // - // (it is often very helpful to explicitly clarify the initial value of - // a local variable-- especially for folks new to more advanced JavaScript - // and who might not recognize the subtle, yet critically important differences between our seemingly - // between `null` and `undefined`, and the impact on `typeof` checks) - "-W080": true - -} From e0640e73193f4259e79725e2513c726c93033447 Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sun, 28 Jun 2020 21:25:06 -0500 Subject: [PATCH 11/16] Add .vscode ignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 806b1b073..72cd44459 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,5 @@ nbproject # misc ############################ dump.rdb + +\.vscode/ From ef4b0044a6d471fa5f18e89dcf3cbcca17a464ae Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sun, 28 Jun 2020 21:25:26 -0500 Subject: [PATCH 12/16] Adds comments about MongoClient in the create manager file --- lib/private/machines/create-manager.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index f7ba34f7e..0eb2bb8ce 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -125,11 +125,15 @@ module.exports = { var mongoUrl = _clientConfig.url; _clientConfig = _.omit(_clientConfig, ['url', 'user', 'password', 'host', 'port', 'database']); + // Use unified topology. MongoDB node maintainers recommends this to be enabled + // https://github.com/mongodb/node-mongodb-native/releases/tag/v3.2.1 + // Use new url parser to remove warnings _clientConfig = Object.assign({ useNewUrlParser: true, useUnifiedTopology: true }, _clientConfig); + // http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html#.connect NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig, function connectCb(err, client) { if (err) { return exits.error(err); From d0b14f684ed6140a76b251fbc0e69ce42e904164 Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sun, 28 Jun 2020 21:25:49 -0500 Subject: [PATCH 13/16] Updates mongodb version, and makes version 1.3.0 for more safety --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0bc9ef5e5..471a94486 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sails-mongo", - "version": "1.2.1", + "version": "1.3.0", "description": "Mongo DB adapter for Sails.js/Waterline.", "main": "./lib", "scripts": { @@ -34,7 +34,7 @@ "async": "3.2.0", "flaverr": "^1.10.0", "machine": "^15.2.2", - "mongodb": "3.5.5", + "mongodb": "3.5.9", "qs": "6.9.4" }, "devDependencies": { From 2a638df2bd2b3e28cca908af5cff22abe2565406 Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sun, 28 Jun 2020 21:26:06 -0500 Subject: [PATCH 14/16] Updates changelog and readme --- CHANGELOG.md | 38 ++++++++++++++++-------------- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 764771494..febe8bf4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,23 @@ # sails-mongo Changelog -### 1.2.1 +### 1.3.0 +* [COMPATIBILITY] Upgrade mongodb driver to version 3.5.9. For more information about breaking changes, check the [Readme](./README.md) file. [@Josebaseba], [@luislobo] +* [DEPENDENCIES] Updates other dependencies to the latest available. [@luislobo] -* [ENHANCEMENT] Adds `npm run start-mongodb` and `npm run stop-mongodb` scripts to start/stop a MongoDB docker instance [@luislobo](@luislobo) -* [ENHANCEMENT] Adds `npm run mongodb-shell` to run a MongoDB Shell CLI that connects to the MongoDB docker instance [@luislobo](@luislobo) -* [INTERNAL] Bump and pin dependency versions [@luislobo](@luislobo) -* [INTERNAL] Tests in Travis run against a combination of Node.js 10, 12, 14 and MongoDB: 3.6, 4.0, 4.2 [@luislobo](@luislobo) -* [INTERNAL] Refactors docker-compose.yml, removing the need of Dockerfile. Updates Docker node version to 12, and MongoDB to 4.2 [@luislobo](@luislobo) +### 1.2.1 +* [ENHANCEMENT] Adds `npm run start-mongodb` and `npm run stop-mongodb` scripts to start/stop a MongoDB docker instance [@luislobo] +* [ENHANCEMENT] Adds `npm run mongodb-shell` to run a MongoDB Shell CLI that connects to the MongoDB docker instance [@luislobo] +* [INTERNAL] Bump and pin dependency versions [@luislobo] +* [INTERNAL] Tests in Travis run against a combination of Node.js 10, 12, 14 and MongoDB: 3.6, 4.0, 4.2 [@luislobo] +* [INTERNAL] Refactors docker-compose.yml, removing the need of Dockerfile. Updates Docker node version to 12, and MongoDB to 4.2 [@luislobo] ### 1.2.0 -* [ENHANCEMENT] Add support for `makeLikeModifierCaseInsensitive` meta key. See [#470](https://github.com/balderdashy/sails-mongo/pull/470) for more details. Thanks [@anterodev](@anterodev)! +* [ENHANCEMENT] Add support for `makeLikeModifierCaseInsensitive` meta key. See [#470](https://github.com/balderdashy/sails-mongo/pull/470) for more details. Thanks [@anterodev]! ### 1.1.0 -* [BUG] Fix issue with aggregation with MongoDB version >=3.4. Now the cursor option is mandatory. [@luislobo](@luislobo) +* [BUG] Fix issue with aggregation with MongoDB version >=3.4. Now the cursor option is mandatory. [@luislobo] ### 1.0.0 @@ -27,29 +30,30 @@ ### 0.12.1 -* [ENHANCEMENT] Sets the `reconnectInterval` to the mongo default and adds a `reconnectTries` configuration option. See [#118](https://github.com/balderdashy/sails-mongo/issues/118) for more details. Thanks [@luislobo](@luislobo) for the patch! +* [ENHANCEMENT] Sets the `reconnectInterval` to the mongo default and adds a `reconnectTries` configuration option. See [#118](https://github.com/balderdashy/sails-mongo/issues/118) for more details. Thanks [@luislobo] for the patch! ### 0.12.0 -* [ENHANCEMENT] Now exposes a flag `wlNext` that allows you to toggle the case sensitivity of a string query. See [#380](https://github.com/balderdashy/sails-mongo/pull/380) and [#238](https://github.com/balderdashy/sails-mongo/pull/238) for more. Thanks [@nicoespeon](@nicoespeon). +* [ENHANCEMENT] Now exposes a flag `wlNext` that allows you to toggle the case sensitivity of a string query. See [#380](https://github.com/balderdashy/sails-mongo/pull/380) and [#238](https://github.com/balderdashy/sails-mongo/pull/238) for more. Thanks [@nicoespeon]. ### 0.11.7 -* [ENHANCEMENT] When running an update only return `_id` values when doing the initial lookup. See [#237](https://github.com/balderdashy/sails-mongo/pull/237) for more. Thanks [@andyhu](@andyhu). +* [ENHANCEMENT] When running an update only return `_id` values when doing the initial lookup. See [#237](https://github.com/balderdashy/sails-mongo/pull/237) for more. Thanks [@andyhu]. -* [ENHANCEMENT] Better error message for duplicate keys when using Wired Tiger. See [#372](https://github.com/balderdashy/sails-mongo/pull/372) for more. Thanks [@Mordred](@Mordred). +* [ENHANCEMENT] Better error message for duplicate keys when using Wired Tiger. See [#372](https://github.com/balderdashy/sails-mongo/pull/372) for more. Thanks [@Mordred]. -* [ENHANCEMENT] Allow multi-line queries when using `contains`, `like`, `startsWith`, and `endsWith`. See [#308](https://github.com/balderdashy/sails-mongo/pull/308) for more. Thanks [@vbud](@vbud). +* [ENHANCEMENT] Allow multi-line queries when using `contains`, `like`, `startsWith`, and `endsWith`. See [#308](https://github.com/balderdashy/sails-mongo/pull/308) for more. Thanks [@vbud]. -* [BUG] Fix issue when returning results with the key `_id` that are not actual ObjectId instances. See [#356](https://github.com/balderdashy/sails-mongo/pull/356) for more. Thanks [@miccar](@miccar). +* [BUG] Fix issue when returning results with the key `_id` that are not actual ObjectId instances. See [#356](https://github.com/balderdashy/sails-mongo/pull/356) for more. Thanks [@miccar]. * [STABILITY] Locked the dependency versions down. --- +[@Josebaseba]: https://github.com/Josebaseba +[@Mordred]: https://github.com/Mordred +[@andyhu]: https://github.com/andyhu [@anterodev]: https://github.com/anterodev [@luislobo]: https://github.com/luislobo +[@miccar]: https://github.com/miccarr [@nicoespeon]: https://github.com/nicoespeon -[@andyhu]: https://github.com/andyhu -[@Mordred]: https://github.com/Mordred [@vbud]: https://github.com/vbud -[@miccar]: https://github.com/miccarr diff --git a/README.md b/README.md index 9b0fb89b1..9ec6b41d3 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,66 @@ Then [connect the adapter](http://sailsjs.com/documentation/reference/configurat Visit [Models & ORM](http://sailsjs.com/docs/concepts/models-and-orm) in the docs for more information about using models, datastores, and adapters in your app/microservice. +## MongoDB Driver +From `sails-mongo` version 1.3.0 and above, the adapter uses [MongoDB driver for Node.js v3.5.9 (or above)](https://www.npmjs.com/package/mongodb). +The updated MongoDB driver changes the way it handles connections internally, and implements the concept of [MongoClient]. + +`manager` still returns a `database`. Access to the [MongoClient] object is done via `manager.client`: +```javascript +// Returns a MongoClient instance +Pet.getDatastore().manager.client +``` + +With access to the [MongoClient] object, now you have access to the latest MongoDB improvements, like [ClientSession], +and with it, transactions, [change streams](https://mongodb.github.io/node-mongodb-native/3.5/api/ChangeStream.html), and other new features. + +#### `.native` still works but you can better use the client + +With `native`: + +```javascript +Pet.native(function (err, collection) { + if (err) { + return res.serverError(err); + } + + collection.find({}, { + name: true + }).toArray(function (err, results) { + if (err) { + return res.serverError(err); + } + res.ok(results); + }); +}); +``` + +with `client`: + +```javascript +try { + // This is an instance of MongoClient + // https://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html + const mongoClient = Pet.getDatastore().manager.client; + const results = await mongoClient.db('test') + .collection('pet') + .find({}, { name: 1 }) + .toArray(); + res.ok(results); +} catch (err) { + res.serverError(err); +} +``` + +## Configuration options +This version uses [MongoDB 3.5.x connection options](https://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html#.connect). + +Check them out as there are some updated, changed, new and deprecated options. + +## Roadmap + +#### NEXT FEATURES TO BE IMPLEMENTED +- Waterline Built-in transactions, instead of using MongoClient ## Compatibility @@ -110,7 +170,6 @@ Thanks so much to Ted Kulp ([@tedkulp](https://twitter.com/tedkulp)) and Robin P To report a bug, [click here](http://sailsjs.com/bugs). - ## License This [core adapter](http://sailsjs.com/documentation/concepts/extending-sails/adapters/available-adapters) is available under the **MIT license**. @@ -120,3 +179,7 @@ As for [Waterline](http://waterlinejs.org) and the [Sails framework](http://sail © [The Sails Co.](http://sailsjs.com/about) ![image_squidhome@2x.png](http://i.imgur.com/RIvu9.png) + +--- +[MongoClient]: https://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html +[ClientSession]: https://mongodb.github.io/node-mongodb-native/3.5/api/ClientSession.html From 69d0cdf9670390946f73c478834e63f463f0a8f0 Mon Sep 17 00:00:00 2001 From: Joseba Legarreta Date: Mon, 16 Nov 2020 11:44:24 +0100 Subject: [PATCH 15/16] Update config-whitelist.constant.js --- lib/private/constants/config-whitelist.constant.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/constants/config-whitelist.constant.js b/lib/private/constants/config-whitelist.constant.js index 207806ac2..d6bcd31ed 100644 --- a/lib/private/constants/config-whitelist.constant.js +++ b/lib/private/constants/config-whitelist.constant.js @@ -16,7 +16,7 @@ module.exports = [ // Connection Options: 'poolSize', 'autoReconnect', 'noDelay', 'keepAlive', 'keepAliveInitialDelay', 'connectTimeoutMS', - 'socketTimeoutMS', 'family', 'reconnectTries', 'reconnectInterval', + 'socketTimeoutMS', 'family', 'reconnectTries', 'reconnectInterval', 'retryWrites', // Other Options: 'ha', 'haInterval', 'replicaSet', 'secondaryAcceptableLatencyMS', From f78f9fc4e6b8ed030befb119096636cdcf8cb7f5 Mon Sep 17 00:00:00 2001 From: Rachael Shaw Date: Mon, 16 Nov 2020 11:45:18 -0600 Subject: [PATCH 16/16] Remove comment that seems out-of-date now --- lib/private/machines/create-manager.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index 0eb2bb8ce..bd64f0d4d 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -139,8 +139,6 @@ module.exports = { return exits.error(err); } - // `db` will be our manager. - // (This variable is just for clarity.) var manager = client.db(_clientConfig.database); manager.client = client;