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.createCollection() does not return a Promise #148

Open
binki opened this issue Mar 18, 2017 · 1 comment
Open

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

binki opened this issue Mar 18, 2017 · 1 comment

Comments

@binki
Copy link

binki commented Mar 18, 2017

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
Copy link

👍
I agree this would be useful!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants