promised-mongo icon indicating copy to clipboard operation
promised-mongo copied to clipboard

Unhandled promise rejection

Open jdnichollsc opened this issue 8 years ago • 5 comments

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

jdnichollsc avatar Nov 22 '16 13:11 jdnichollsc

ah!,you can try db.authors.insert

send2ocean avatar Dec 09 '16 06:12 send2ocean

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.

ChJJin avatar Dec 21 '16 16:12 ChJJin

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?

cristiandan avatar Dec 22 '16 19:12 cristiandan

No, the collection has been created before. And db.authors.insert works after that without throwing another error.

ChJJin avatar Dec 26 '16 08:12 ChJJin

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?

GuillaumeUnice avatar Apr 25 '17 11:04 GuillaumeUnice