Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(createCollection): Db.createCollection should pass readConcern to new collection #2026

Merged
merged 13 commits into from
Jun 21, 2019
2 changes: 1 addition & 1 deletion lib/core/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,10 @@ function applySession(session, command, options) {
session.transaction.transition(TxnState.NO_TRANSACTION);
}

// TODO: the following should only be applied to read operation per spec.
rosemaryy marked this conversation as resolved.
Show resolved Hide resolved
// for causal consistency
if (session.supports.causalConsistency && session.operationTime) {
command.readConcern = command.readConcern || {};
console.log('this is the command!! : ', command);
Object.assign(command.readConcern, { afterClusterTime: session.operationTime });
}

Expand Down
4 changes: 3 additions & 1 deletion lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ Db.prototype.createCollection = deprecateOptions(
if (typeof options === 'function') (callback = options), (options = {});
options = options || {};
options.promiseLibrary = options.promiseLibrary || this.s.promiseLibrary;

options.readConcern = options.readConcern
? new ReadConcern(options.readConcern.level)
: this.readConcern;
const createCollectionOperation = new CreateCollectionOperation(this, name, options);

return executeOperation(this.s.topology, createCollectionOperation, callback);
Expand Down
4 changes: 4 additions & 0 deletions test/functional/readconcern_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ describe('ReadConcern', function() {
var collection = db.collection('readConcernCollection');
// Validate readConcern
test.deepEqual({ level: 'local' }, collection.s.readConcern);
// create a collection using createCollection
rosemaryy marked this conversation as resolved.
Show resolved Hide resolved
var createdCollection = db.createCollection('readConcernCollection');
// validate readConcern
test.deepEqual({ level: 'local' }, createdCollection.s.readConcern);
rosemaryy marked this conversation as resolved.
Show resolved Hide resolved
// Perform a find using the readConcern
listener.on('started', function(event) {
if (event.commandName === 'find') started.push(event);
Expand Down
3 changes: 2 additions & 1 deletion test/functional/view_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ describe('Views', function() {
expect(commandResult).to.eql({
create: 'test',
viewOn: 'users',
pipeline: [{ $match: {} }]
pipeline: [{ $match: {} }],
readConcern: {}
});

client.close();
Expand Down