如何在Mongoid

时间:2017-02-16 09:09:03

标签: mongodb mongoid

好的,我想查询MongoID以再次检查一个参数。想象一下,我有start_dateend_date作为我的模型的属性。我想像这样查询Mongoid:

Model.where(start_date > end_date)

那我怎么能这样做?如果我使用MongoDB控制台,我会做(未经测试):

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

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

你可以尝试

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

或在Mongoid 3中

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