promised-mongo
promised-mongo copied to clipboard
Unhandled promise rejection
Hi guys,
I'm trying to insert a document:
var author = { _id: '123', name: 'John Carter' };
return authorsCollection.insert(author);
But I've the following error:
(node:9632) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot create property '_id' on string 'local.authors'
Thanks in advance, Nicholls
ah!,you can try db.authors.insert
Hi,
I got the same error, and it works for me to use db.authors.insert
instead. But I want to know whether I use it incorrectly or it's a bug. Thanks.
Isn't it a problem with your connection? Because then it would make sense that the collection object isn't created. If you have:
const db = mongo('mongodb://RemoteConnectionString');
const authorsCollection = db.collection('authors');
and the connection to the remote server fails, the authorsCollection object isn't initialized.
Does db.authors.insert
work all the way up to inserting in the db? Or does it throw another error?
No, the collection has been created before. And db.authors.insert
works after that without throwing another error.
Hi, Same things for me and I just want to know why
db.authors.insert
and not
authorsCollection.insert(author);
It's a spec update?