Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Mongoid中运行MongoDB本机查询_Mongodb_Mongoid - Fatal编程技术网

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

如何在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') 或者

好的,我想查询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') 
或者在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')
?不,我还没有,现在完成后,它就可以工作了。是否要添加作为答案?