Mongoid batch collection insertion: how to get IDs of newly created items?
As explained here , it's pretty easy to batch-insert an array of new documents into a MongoDB collection:
batch = [{:name => "mongodb"}, {:name => "mongoid"}]
Article.collection.insert(batch)
What is not easy for me is how to get the list of newly created ids. Is it possible to code something like:
batch = [{:name => "mongodb"}, {:name => "mongoid"}]
result = Article.collection.insert(batch)
result[:ids] # not real code
Thanks in advance!
+3
source to share
No one has answered this question yet
See similar questions:
or similar: