diff --git a/lib/query.js b/lib/query.js index 35866f7f2a..f78ef43b72 100644 --- a/lib/query.js +++ b/lib/query.js @@ -1141,6 +1141,51 @@ Query.prototype.wtimeout = function wtimeout(ms) { return this; }; +/** + * Sets the readConcern option for the query. + * + * ####Example: + * + * new Query().readConcern('local') + * new Query().readConcern('l') // same as local + * + * new Query().readConcern('available') + * new Query().readConcern('a') // same as available + * + * new Query().readConcern('majority') + * new Query().readConcern('m') // same as majority + * + * new Query().readConcern('linearizable') + * new Query().readConcern('lz') // same as linearizable + * + * new Query().readConcern('snapshot') + * new Query().readConcern('s') // same as snapshot + * + * + * ####Read Concern Level: + * + * local MongoDB 3.2+ The query returns from the instance with no guarantee guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back). + * available MongoDB 3.6+ The query returns from the instance with no guarantee guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back). + * majority MongoDB 3.2+ The query returns the data that has been acknowledged by a majority of the replica set members. The documents returned by the read operation are durable, even in the event of failure. + * linearizable MongoDB 3.4+ The query returns data that reflects all successful majority-acknowledged writes that completed prior to the start of the read operation. The query may wait for concurrently executing writes to propagate to a majority of replica set members before returning results. + * snapshot MongoDB 4.0+ Only available for operations within multi-document transactions. Upon transaction commit with write concern "majority", the transaction operations are guaranteed to have read from a snapshot of majority-committed data. + * + * Aliases + * + * l local + * a available + * m majority + * lz linearizable + * s snapshot + * + * Read more about how to use read concern [here](https://docs.mongodb.com/manual/reference/read-concern/). + * + * @param {String} level one of the listed read concern level or their aliases + * @see mongodb https://docs.mongodb.com/manual/reference/read-concern/ + * @return {Query} this + * @api public + */ + /** * Merges another Query or conditions object into this one. * diff --git a/package.json b/package.json index ffa5f5ce82..8947d9e438 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "mongodb-core": "3.1.0", "mongoose-legacy-pluralize": "1.0.2", "mpath": "0.4.1", - "mquery": "3.0.0", + "mquery": "3.1.1", "ms": "2.0.0", "regexp-clone": "0.0.1", "sliced": "1.0.1" diff --git a/test/query.test.js b/test/query.test.js index 943ed27ec6..23f1812631 100644 --- a/test/query.test.js +++ b/test/query.test.js @@ -749,9 +749,9 @@ describe('Query', function() { if (typeof global.Map !== 'undefined') { query = new Query({}, {}, null, p1.collection); - query.sort(new global.Map().set('a', 1).set('b', 2)); + query.sort(new global.Map().set('a', 1).set('b', 1)); assert.equal(query.options.sort.get('a'), 1); - assert.equal(query.options.sort.get('b'), 2); + assert.equal(query.options.sort.get('b'), 1); } query = new Query({}, {}, null, p1.collection);