From 6fd05c1ef8dfb495bf16805f541c94aac132df84 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Sat, 6 Jan 2018 11:53:50 -0500 Subject: [PATCH] feat(collection): expose `dbName` property of collection NODE-1242 --- lib/collection.js | 7 +++++++ test/functional/collection_tests.js | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/collection.js b/lib/collection.js index a0d4f44ccf..2d70e6e003 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -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() { diff --git a/test/functional/collection_tests.js b/test/functional/collection_tests.js index 2127b22730..b9a38caeff 100644 --- a/test/functional/collection_tests.js +++ b/test/functional/collection_tests.js @@ -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(); + }); + } + }); });