Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db.collections function #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ var Db = module.exports = function(dbname, server) {
collectionNames: function() {
return _.map(backingstore.collections, function(c) { return c.name; });
},
collections: function(session){
if(session) NotImplemented();
return backingstore.collections;
},
logout: NotImplemented,
open: function(callback) {
asyncish(function () {
Expand Down
27 changes: 27 additions & 0 deletions test/mock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ describe('mock tests', function () {
});
});
});
it('should list collections', function(done) {
var collectionName1 = "test_databases_collectionNames_collection_1";
var collectionName2 = "test_databases_collectionNames_collection_2";
var collectionName3 = "test_databases_collectionNames_collection_3";
connected_db.createCollection(collectionName1, function(err, listCollection) {
if(err) return done(err);
connected_db.createCollection(collectionName3, function(err, listCollection) {
if(err) return done(err);
connected_db.createCollection(collectionName2, function(err, listCollection) {
if(err) return done(err);
var collections = connected_db.collections();
var collectionNames = connected_db.collectionNames();
const names = collections.map(item => item.collectionName)
names.should.be.eql(collectionNames);
done();
});
});
});
});
it('should throw Not Implemented error', function(done) {
try{
connected_db.collections({});
}catch(e){
e.message.should.be.eql('Not Implemented. PR welcome!');
done();
}
});
it('should drop collection', function (done) {
var dropCollectionName = "test_databases_dropCollection_collection";
connected_db.createCollection(dropCollectionName, function (err, dropCollection){
Expand Down