Browse Source

Implement listCollections and use listCollections to implement getCollectionNames

saintedlama/travis-non-legacy
saintedlama 9 years ago
parent
commit
4c407e3f53
  1. 16
      lib/database.js

16
lib/database.js

@ -104,20 +104,24 @@ Database.prototype.runCommand = function (opts, cb) {
})
}
Database.prototype.getCollectionNames = function (cb) {
function mapCollectionNames (collection) {
return collection.name
}
Database.prototype.listCollections = function (cb) {
this._getConnection(function (err, connection) {
if (err) { return cb(err) }
connection.listCollections().toArray(function (err, collections) {
if (err) { return cb(err) }
cb(null, collections.map(mapCollectionNames))
cb(null, collections)
})
})
}
Database.prototype.getCollectionNames = function (cb) {
this.listCollections(function (err, collections) {
if (err) { return cb(err) }
cb(null, collections.map(function (collection) { return collection.name }))
})
}
Database.prototype.createCollection = function (name, opts, cb) {
if (typeof opts === 'function') return this.createCollection(name, {}, opts)

Loading…
Cancel
Save