简体   繁体   English

如何在Mongoid中运行MongoDB本机查询

[英]How to run a MongoDB native query in Mongoid

Ok, I'd like to query MongoID to check one parameter agains another. 好的,我想查询MongoID再次检查一个参数。 Imagine I have start_date and end_date as properties of my Model. 想象一下,我将start_dateend_date作为我的模型的属性。 I'd like to query Mongoid like so: 我想像这样查询Mongoid:

Model.where(start_date > end_date)

So how can I do that? 那我该怎么办呢? If I were to use MongoDB console, I'd do something like (untested): 如果我使用MongoDB控制台,我会做(未经测试)的事情:

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

Any ideas? 有任何想法吗?

You could try 你可以试试

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

or in Mongoid 3 as 或者在Mongoid 3中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM