Insert and ObjectId

17 views
Skip to first unread message

Henrique Nunes

unread,
Feb 19, 2014, 6:52:33 AM2/19/14
to clojure...@googlegroups.com
Hi all.

In the docs, there's this

monger.collection/insert-and-return is an alternative insertion function that returns the exact documented inserted, including the generated document id:

then this 

It is highly recommended to always store documents with the :_id key set. If you need a generated object id. 

So, does insert-and-return address the object id generation concern above, or should I be generating and merging object ids when inserting with insert-and-return anyway?

Also, how do I check for write errors when using insert-and-return? Is it possible at all?

Thanks!
Henrique

Henrique Nunes

unread,
Feb 19, 2014, 6:55:23 AM2/19/14
to clojure...@googlegroups.com
Ok,

I can see insert-and-return actually generates and merges the object id before sending the document to the java driver. So that takes care of the first question.

What about the error checking though? What's the recommended approach here?

Thanks,
Henrique

Michael Klishin

unread,
Feb 19, 2014, 7:11:28 AM2/19/14
to Monger, a Clojure MongoDB driver
2014-02-19 15:55 GMT+04:00 Henrique Nunes <hjrn...@gmail.com>:
What about the error checking though? What's the recommended approach here?

https://github.com/michaelklishin/monger/blob/master/src/clojure/monger/core.clj#L280

Because returning a pair from insert-and-return would make it less natural to use, we decided
we'll have to ask people to use get-last-error. If you want a WriteResult back, you can always pass
:_id to insert.
--
MK

http://github.com/michaelklishin
http://twitter.com/michaelklishin
Reply all
Reply to author
Forward
0 new messages