Skip to content

Commit ec88b07

Browse files
committed
fix(db): don't remove database name if collectionName == dbName
NODE-972
1 parent 578fd84 commit ec88b07

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/db.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ var collections = function(self, callback) {
937937

938938
// Return the collection objects
939939
handleCallback(callback, null, documents.map(function(d) {
940-
return new Collection(self, self.s.topology, self.s.databaseName, d.name.replace(self.s.databaseName + ".", ''), self.s.pkFactory, self.s.options);
940+
return new Collection(self, self.s.topology, self.s.databaseName, d.name, self.s.pkFactory, self.s.options);
941941
}));
942942
});
943943
}

test/functional/db_tests.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,29 @@ exports.shouldCorrectlyReconnectWhenError = {
332332
}
333333
}
334334

335+
exports['should not cut collection name when it is the same as the database'] = {
336+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
337+
338+
test: function(configuration, test) {
339+
var db = configuration.newDbInstance(configuration.writeConcernMax(), { poolSize:1, auto_reconnect: false });
340+
db.open(function(err, db) {
341+
test.equal(null, err);
342+
343+
var db1 = db.db('node972');
344+
db1.collection('node972.test').insertOne({ a: 1 }, function(err) {
345+
test.equal(null, err);
346+
347+
db1.collections(function(err, collections) {
348+
test.equal(null, err);
349+
collections = collections.map(function(c) { return c.collectionName; });
350+
test.notEqual(-1, collections.indexOf('node972.test'));
351+
test.done();
352+
});
353+
});
354+
});
355+
}
356+
}
357+
335358
/**
336359
* @ignore
337360
*/

0 commit comments

Comments
 (0)