Skip to content

Commit

Permalink
fix(query): upgrade mquery for readConcern() helper
Browse files Browse the repository at this point in the history
Fix #6777
  • Loading branch information
vkarpov15 committed Jul 30, 2018
1 parent 2bf81e7 commit 2b5e18a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
45 changes: 45 additions & 0 deletions lib/query.js
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/query.test.js
Expand Up @@ -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);
Expand Down

0 comments on commit 2b5e18a

Please sign in to comment.