tingodb icon indicating copy to clipboard operation
tingodb copied to clipboard

Db.createCollection() does not return a Promise

Open binki opened this issue 7 years ago • 1 comments

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

binki avatar Mar 18 '17 23:03 binki

👍 I agree this would be useful!

At the moment I've wrapped the callback into a new Promise to handle the scenario.

ImTheDeveloper avatar Nov 12 '17 05:11 ImTheDeveloper