Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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
Ruby on rails Ruby中的MongoDb排序_Ruby On Rails_Ruby_Mongodb - Fatal编程技术网

Ruby on rails Ruby中的MongoDb排序

Ruby on rails Ruby中的MongoDb排序,ruby-on-rails,ruby,mongodb,Ruby On Rails,Ruby,Mongodb,我必须通过mongodb驱动程序在ruby中对mongodb集合进行排序 db.zipper.find().sort({"value":-1}) 但是当我在ruby中做同样的事情时,集合并没有得到排序 coll = db.collection('zipper') coll.find().sort({"value":-1}) 告诉我哪里出了问题,我试过了 coll.find.sort(:value,:desc) 但是这也是徒劳的。告诉我哪里出错了。您需要将排序选项作为键值对数组传递,例如:

我必须通过mongodb驱动程序在ruby中对mongodb集合进行排序

db.zipper.find().sort({"value":-1})
但是当我在ruby中做同样的事情时,集合并没有得到排序

coll = db.collection('zipper')
coll.find().sort({"value":-1})
告诉我哪里出了问题,我试过了

coll.find.sort(:value,:desc) 

但是这也是徒劳的。告诉我哪里出错了。

您需要将排序选项作为键值对数组传递,例如:

 coll.find({}, :sort => ['value',-1])
使用Ruby驱动程序,您还可以使用desc或descending作为-1反向排序顺序的语义等价物:

 coll.find({}, :sort => ['value','desc'])
 coll.find({}, :sort => ['value','descending'])

您需要将排序选项作为键值对数组传递,例如:

 coll.find({}, :sort => ['value',-1])
使用Ruby驱动程序,您还可以使用desc或descending作为-1反向排序顺序的语义等价物:

 coll.find({}, :sort => ['value','desc'])
 coll.find({}, :sort => ['value','descending'])

对于较新的Ruby和Mongo驱动程序,您可以使用如下哈希语法:

coll.find{},sort:{value:-1}
对于较新的Ruby和Mongo驱动程序,您可以使用如下哈希语法:

coll.find{},sort:{value:-1}
在我将数组更改为object::sort=>{'value'=>-1}后,它对我有效。在我将数组更改为object::sort=>{'value'=>-1}后,它对我有效