tingodb
tingodb copied to clipboard
Db.createCollection() does not return a Promise
Db.createCollection()
should return a Promise
yielding Collection
like the mongo node API does.
From the example at https://mongodb.github.io/node-mongodb-native/2.2/api/Db.html#createCollection :
db.createCollection("a_simple_collection_2_with_promise", {capped:true, size:100000, max:10000, w:1}).then(function(collection) {
This enables standard Promise
based error handling to detect errors during collection creation (rather than having to use the callbacks). If I understand correctly, this is an API inconsistency with MongoDB.
The following fails when I expect it to work:
const db = new Db(dbPath, {});
db.createCollection('asdf', {}).then(collection => {
console.log(collection);
});
TypeError: db.createCollection(...).then is not a function
👍 I agree this would be useful!
At the moment I've wrapped the callback into a new Promise to handle the scenario.