sergeyksv / tingodb

Embedded Node.js database upward compatible with MongoDB
www.tingodb.com
1.16k stars 105 forks source link

Db.createCollection() does not return a Promise #148

Open binki opened 7 years ago

binki commented 7 years ago

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
ImTheDeveloper commented 7 years ago

👍 I agree this would be useful!

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