Skip to content

Commit b8471f1

Browse files
authoredJul 20, 2018
fix(collection): isCapped returns false instead of undefined
The collection method isCapped was returning undefined when the capped option was either unspecified or specified as false. Fixes NODE-1380
1 parent 86344f4 commit b8471f1

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎lib/operations/collection_ops.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ function insertOne(coll, doc, options, callback) {
846846
function isCapped(coll, options, callback) {
847847
optionsOp(coll, options, (err, document) => {
848848
if (err) return handleCallback(callback, err);
849-
handleCallback(callback, null, document && document.capped);
849+
handleCallback(callback, null, !!(document && document.capped));
850850
});
851851
}
852852

‎test/functional/collection_tests.js

+25
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,31 @@ describe('Collection', function() {
17801780
});
17811781
});
17821782

1783+
function testCapped(config, done) {
1784+
const configuration = config.config;
1785+
const client = new MongoClient(configuration.url(), { w: 1 });
1786+
1787+
client.connect(function(err, client) {
1788+
const db = client.db(configuration.db);
1789+
const close = e => client.close(() => done(e));
1790+
1791+
db
1792+
.createCollection(config.collName, config.opts)
1793+
.then(collection => collection.isCapped())
1794+
.then(capped => expect(capped).to.be.false)
1795+
.then(() => close())
1796+
.catch(e => close(e));
1797+
});
1798+
}
1799+
1800+
it('isCapped should return false for uncapped collections', function(done) {
1801+
testCapped({ config: this.configuration, collName: 'uncapped', opts: { capped: false } }, done);
1802+
});
1803+
1804+
it('isCapped should return false for collections instantiated without specifying capped', function(done) {
1805+
testCapped({ config: this.configuration, collName: 'uncapped2', opts: {} }, done);
1806+
});
1807+
17831808
describe('Retryable Writes on bulk ops', function() {
17841809
const MongoClient = require('../../lib/mongo_client');
17851810

0 commit comments

Comments
 (0)
Please sign in to comment.