Ruby MongoDB/Mongoid排序行为怪异
我有以下目标:Ruby MongoDB/Mongoid排序行为怪异,ruby,mongodb,mongoid,sorting,Ruby,Mongodb,Mongoid,Sorting,我有以下目标: class Node include Mongoid::Document include Mongoid::Tree field :path, type: Array end path数组用于存储树中的全局位置,因此根节点将存储其位置:{path:[0]},子节点将存储其位置和根位置:{path:[0,0]} 当我使用Node.asc(:path)查询它们,然后询问路径时,我得到如下结果: [[3, 0, 0], [7, 0], # WTF?
class Node
include Mongoid::Document
include Mongoid::Tree
field :path, type: Array
end
path
数组用于存储树中的全局位置,因此根节点将存储其位置:{path:[0]}
,子节点将存储其位置和根位置:{path:[0,0]}
当我使用Node.asc(:path)
查询它们,然后询问路径时,我得到如下结果:
[[3, 0, 0],
[7, 0], # WTF?
[3, 0],
[2, 0, 1],
[2, 0],
[2, 0, 0, 0],
[0],
…
]
然而,当我在Ruby中进行排序时,我得到了正确的结果:
[[0],
[2],
[2, 0],
[2, 0, 0],
[2, 0, 0, 0],
[2, 0, 1],
[2, 0, 1, 0],
[3],
…
]
MongoDB是怎么回事,这与索引有关吗