Tuesday, 23 July 2019

mongodb nodejs driver await .

can i use await?

according to below links , yes, you can:



but await only works for creating connecting:

await MongoClient.connect(this.connectionString, {'useNewUrlParser': true});

it doesn't work with update insert functions.....  don't know why. (maybe i should use updateOne?)

so i have to use co and generator as the official document suggested:


note if you run the sample code with 3.+ mongo driver, then you cannot put the database name into the URI, you need to call : client.db function to get the db instance :

var client = yield MongoClient.connect(connectionString)
var db = client.db(dbName);

No comments:

Post a comment