2017-02-16 46 views
1

好的,我想查询MongoID以再次检查一个参数。想象一下,我有start_dateend_date作为我的模型的属性。我想要这样查询Mongoid:如何在Mongoid中运行MongoDB本地查询

Model.where(start_date > end_date) 

那么我该怎么做呢?如果我要使用MongoDB控制台,我会做类似(未经测试):

db.collection.find({$where: "this.end_date > this.start_date"}).count() 

任何想法?

+1

你试过'Model.collection.find( '$其中'=> 'this.end_date> this.start_date' )'或在Mongoid 3中作为'Model.where('this.end_date> this.start_date')'? – chridam

+0

不,我没有,一旦我现在完成,它的工作。你想添加一个答案吗? – WagnerMatosUK

回答

0

你可以尝试

Model.collection.find('$where' => 'this.end_date > this.start_date') 

或Mongoid 3作为

Model.where('this.end_date > this.start_date')