Skip to content

Commit 6fd05c1

Browse files
committed
feat(collection): expose dbName property of collection
NODE-1242
1 parent 1fb74cd commit 6fd05c1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/collection.js

+7
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ var Collection = function(db, topology, dbName, name, pkFactory, options) {
143143

144144
var define = (Collection.define = new Define('Collection', Collection, false));
145145

146+
Object.defineProperty(Collection.prototype, 'dbName', {
147+
enumerable: true,
148+
get: function() {
149+
return this.s.dbName;
150+
}
151+
});
152+
146153
Object.defineProperty(Collection.prototype, 'collectionName', {
147154
enumerable: true,
148155
get: function() {

test/functional/collection_tests.js

+24
Original file line numberDiff line numberDiff line change
@@ -1556,4 +1556,28 @@ describe('Collection', function() {
15561556
});
15571557
}
15581558
});
1559+
1560+
/**
1561+
* @ignore
1562+
*/
1563+
it('should provide access to the database name', {
1564+
metadata: {
1565+
requires: { topology: ['single'] }
1566+
},
1567+
1568+
test: function() {
1569+
var self = this;
1570+
var client = self.configuration.newClient(self.configuration.writeConcernMax(), {
1571+
poolSize: 1
1572+
});
1573+
1574+
return client
1575+
.connect()
1576+
.then(client => client.db('test_db').createCollection('test1'))
1577+
.then(coll => {
1578+
expect(coll.dbName).to.equal('test_db');
1579+
return client.close();
1580+
});
1581+
}
1582+
});
15591583
});

0 commit comments

Comments
 (0)