Skip to content

Commit

Permalink
feat(collection): expose dbName property of collection
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Jan 10, 2018
1 parent 1fb74cd commit 6fd05c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ var Collection = function(db, topology, dbName, name, pkFactory, options) {

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

Object.defineProperty(Collection.prototype, 'dbName', {
enumerable: true,
get: function() {
return this.s.dbName;
}
});

Object.defineProperty(Collection.prototype, 'collectionName', {
enumerable: true,
get: function() {
Expand Down
24 changes: 24 additions & 0 deletions test/functional/collection_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1556,4 +1556,28 @@ describe('Collection', function() {
});
}
});

/**
* @ignore
*/
it('should provide access to the database name', {
metadata: {
requires: { topology: ['single'] }
},

test: function() {
var self = this;
var client = self.configuration.newClient(self.configuration.writeConcernMax(), {
poolSize: 1
});

return client
.connect()
.then(client => client.db('test_db').createCollection('test1'))
.then(coll => {
expect(coll.dbName).to.equal('test_db');
return client.close();
});
}
});
});

0 comments on commit 6fd05c1

Please sign in to comment.