Mongoid/RubyDriver ContinueOnError not working

98 views
Skip to first unread message

Daniel Schlegel

unread,
Aug 2, 2012, 8:40:57 AM8/2/12
to mongod...@googlegroups.com
Hi 
I try to do inserts in monogo with mongoid. unfortunately the continue_on_error option does not work.

Situation:
There is an index on :name

documents = [{:name => "First"}, {:name => "Second"}]

# following line works like expected.
MyCollection.collection.insert(documents, :continue_on_error => true, :safe => false)
# => First and Second in DB

documents = [{:name => "First"}, {:name => "Third"}]
MyCollection.collection.insert(documents, :continue_on_error => true, :safe => false)
# => Third not in DB.

i don't get an exception while inserting, but it seames, that the batch stop it's processing when error occured.

Thanks for your help.


Emily S

unread,
Aug 2, 2012, 12:13:28 PM8/2/12
to mongod...@googlegroups.com
Hi

This seems to work for me:

> db['things'].create_index("name", :unique => true)
> documents = [{:name => "First"}, {:name => "Second"}]
> db['things'].insert(documents, :continue_on_error => true, :safe => false)

in the mongo shell:
> db.things.find()
{ "_id" : ObjectId("501a9cf13005c82ac9000001"), "name" : "First" }
{ "_id" : ObjectId("501a9cf13005c82ac9000002"), "name" : "Second" }

> documents = [{:name => "First"}, {:name => "Third"}]
> db['things'].insert(documents, :continue_on_error => true, :safe => false)

in the mongo shell:
> db.things.find()
{ "_id" : ObjectId("501a9cf13005c82ac9000001"), "name" : "First" }
{ "_id" : ObjectId("501a9cf13005c82ac9000002"), "name" : "Second" }
{ "_id" : ObjectId("501a9d173005c82ac9000004"), "name" : "Third" }

You shouldn't be getting an exception if you use :safe => false
What version of Mongoid are you using?

Daniel Schlegel

unread,
Aug 2, 2012, 2:33:59 PM8/2/12
to mongod...@googlegroups.com
Hi Emily
Thank you very much. I tried on a different machine now and there it worked. 
Now i found out, that on the maschine i tried an old mongodb server but new client was running. 

Sorry for wasting your time. this was my fault.
Reply all
Reply to author
Forward
0 new messages