[英]How to run a MongoDB native query in Mongoid
好的,我想查询MongoID再次检查一个参数。 想象一下,我将start_date
和end_date
作为我的模型的属性。 我想像这样查询Mongoid:
Model.where(start_date > end_date)
那我该怎么办呢? 如果我使用MongoDB控制台,我会做(未经测试)的事情:
db.collection.find({$where: "this.end_date > this.start_date"}).count()
有任何想法吗?
你可以试试
Model.collection.find('$where' => 'this.end_date > this.start_date')
或者在Mongoid 3中
Model.where('this.end_date > this.start_date')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.