如何在Mongoid中运行MongoDB本机查询
好的,我想查询MongoID以检查一个参数和另一个参数。假设我有如何在Mongoid中运行MongoDB本机查询,mongodb,mongoid,Mongodb,Mongoid,好的,我想查询MongoID以检查一个参数和另一个参数。假设我有start\u date和end\u date作为模型的属性。我想这样询问Mongoid: Model.where(start_date > end_date) 那我该怎么做呢?如果我使用MongoDB控制台,我会做一些类似(未测试)的事情: 有什么想法吗?你可以试试 Model.collection.find('$where' => 'this.end_date > this.start_date') 或者
start\u date
和end\u date
作为模型的属性。我想这样询问Mongoid:
Model.where(start_date > end_date)
那我该怎么做呢?如果我使用MongoDB控制台,我会做一些类似(未测试)的事情:
有什么想法吗?你可以试试
Model.collection.find('$where' => 'this.end_date > this.start_date')
或者在Mongoid 3中作为
Model.where('this.end_date > this.start_date')
你可以试试
Model.collection.find('$where' => 'this.end_date > this.start_date')
或者在Mongoid 3中作为
Model.where('this.end_date > this.start_date')
您是否尝试过
Model.collection.find('$where'=>'this.end\u date>this.start\u date')
或在Mongoid 3中作为Model.where('this.end\u date>this.start\u date')
?不,我还没有,现在一旦完成,它就可以工作了。是否要添加作为答案?是否尝试了Model.collection.find(“$where'=>”this.end\u date>this.start\u date”)
或在Mongoid 3中添加为Model.where('this.end\u date>this.start\u date')
?不,我还没有,现在完成后,它就可以工作了。是否要添加作为答案?