forked from balderdashy/sails-mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Temporarily revert merged PR balderdashy#483"
This reverts commit 384758b.
- Loading branch information
1 parent
4d0d2bb
commit 6f02ce2
Showing
12 changed files
with
119 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,5 @@ nbproject | |
# misc | ||
############################ | ||
dump.rdb | ||
|
||
\.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
![[email protected]](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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
'poolSize', 'autoReconnect', 'noDelay', 'keepAlive', 'keepAliveInitialDelay', 'connectTimeoutMS', | ||
'socketTimeoutMS', 'family', 'reconnectTries', 'reconnectInterval', 'retryWrites', | ||
|
||
// 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' | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.