datanoise / mongo.cr

Crystal binding for MongoDB C Driver
MIT License
97 stars 35 forks source link

Getting the _id of an inserted document #4

Closed dbackeus closed 9 years ago

dbackeus commented 9 years ago

Since Collection#insert returns nil, any idea how to find out what _id mongodb auto-added to the new document?

datanoise commented 9 years ago

You need to use last_error method. I believe there is a comment to insert

dbackeus commented 9 years ago

Right you are :+1:

codenoid commented 6 years ago

i just got

{ "nInserted" : 1, "nMatched" : 0, "nModified" : 0, "nRemoved" : 0, "nUpserted" : 0, "writeErrors" : [  ] }

from .last_error :( @datanoise