Skip to content

Commit

Permalink
fix(collection): isCapped returns false instead of undefined
Browse files Browse the repository at this point in the history
The collection method isCapped was returning undefined
when the capped option was either unspecified or specified
as false.

Fixes NODE-1380
  • Loading branch information
rweinberger authored Jul 20, 2018
1 parent 86344f4 commit b8471f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/operations/collection_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ function insertOne(coll, doc, options, callback) {
function isCapped(coll, options, callback) {
optionsOp(coll, options, (err, document) => {
if (err) return handleCallback(callback, err);
handleCallback(callback, null, document && document.capped);
handleCallback(callback, null, !!(document && document.capped));
});
}

Expand Down
25 changes: 25 additions & 0 deletions test/functional/collection_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,31 @@ describe('Collection', function() {
});
});

function testCapped(config, done) {
const configuration = config.config;
const client = new MongoClient(configuration.url(), { w: 1 });

client.connect(function(err, client) {
const db = client.db(configuration.db);
const close = e => client.close(() => done(e));

db
.createCollection(config.collName, config.opts)
.then(collection => collection.isCapped())
.then(capped => expect(capped).to.be.false)
.then(() => close())
.catch(e => close(e));
});
}

it('isCapped should return false for uncapped collections', function(done) {
testCapped({ config: this.configuration, collName: 'uncapped', opts: { capped: false } }, done);
});

it('isCapped should return false for collections instantiated without specifying capped', function(done) {
testCapped({ config: this.configuration, collName: 'uncapped2', opts: {} }, done);
});

describe('Retryable Writes on bulk ops', function() {
const MongoClient = require('../../lib/mongo_client');

Expand Down

0 comments on commit b8471f1

Please sign in to comment.