mongodb - Using upsert with push to an array option on Ruby driver -



mongodb - Using upsert with push to an array option on Ruby driver -

i'm trying upsert ruby driver mongodb. if row exist wish force new info , array, else create new document 1 item in array.

when run on mongodb looks that:

db.events.update( { "_id" : objectid("4f0ef9171d41c85a1b000001")}, { $push : { "events" : { "field_a" : 1 , "field_b" : "2"}}}, true)

and works.

when run on ruby looks that:

@col_events.update( { "_id" => bson::objectid.from_string("4f0ef9171d41c85a1b000001")}, { :$push => { "events" => { "field_a" => 1 , "field_b" => "2"}}}, :$upsert=>true)

and doesn't work. don't error don't see new rows either.

will appreciate help in understanding doing wrong.

so couple of issues.

in ruby, command should :upsert=>true. note there not $. docs here. you not running query :safe=>true. means exceptions not fire. causing exception on server, not waiting server acknowledge write.

ruby mongodb

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -