1

I am trying to update the mongodb embedded collection using the $ positional operator from ruby mongoid, but it is not working. Below the mongoid query

Viewcounter.collection.update({:item_id=>BSON::ObjectId('yyyy'),'viewinfos.remote_ip' => 'xxxx'},{'$inc' => {'viewinfos.$.viewcount' => 1}})

After some more digging i found that no mongodb queries works with mongoid update.including below simple query

Item.collection.update({'_id' =>BSON::ObjectId('sss')},{:isused => false})

has anyone got a better way of doing the positional operator queries with mongoid?

EDIT

But as per the mongodb official ruby driver documentation, this should work. below the excerpt

coll.update({"_id" => doc["_id"]}, {"$set" => {"name" => "MongoDB Ruby"}})
4

1 回答 1

4

一般的想法是你会下拉到 ruby​​ 驱动程序(通过集合)并这样做:

Viewcounter.collection.update({"viewinfos.remote_ip" => "xxxx"}, {:$inc => {"viewinfos.$.viewcount" => 1}})
于 2011-12-12T14:39:24.170 回答