0
比較單獨列我在尋找的mongoid相當於: How to select the comparison of two columns as one column in Oracle在Mongoid
我似乎無法找到任何文件或在同一查詢中比較列的例子。這在Mongoid中是不可能的嗎?
比較單獨列我在尋找的mongoid相當於: How to select the comparison of two columns as one column in Oracle在Mongoid
我似乎無法找到任何文件或在同一查詢中比較列的例子。這在Mongoid中是不可能的嗎?
不,你需要下降到MongoDB的紅寶石司機要做到這一點,這將可能是非常慢的,因爲它是不會使用索引一個javascript查詢:
Model.collection.find_one({"$where" => 'this.name == this.name2'})
即相當於第三shell命令:這裏
> db.collection.insert({name: "awesome", name2: "awesome"})
> db.collection.insert({name: "awesome", name2: "awesome2"})
> db.collection.find('this.name == this.name2')
{ "_id" : ObjectId("xxx"), "name" : "awesome", "name2" : "awesome" }
> (line shown to signify end of results)
注:如果文件沒有關鍵name
和同一文檔也沒有鑰匙name2
,這將返回true,因爲空== NULL。
從我可以告訴,Model.collection.find_one()只採用常規選擇器,而不是任意的JavaScript。 – LanceH 2012-02-06 20:40:39
更新了命令以使用$ where,檢查出來。 – 2012-02-06 21:24:53
我需要更改$到哪裏「$哪裏」,然後它的工作,謝謝。 – LanceH 2012-02-06 22:06:54