簡體   English   中英

MongoDB $orderby 和 $sort 都不起作用

[英]MongoDB $orderby and $sort both not Working

我有以下格式的 MongoDB 集合:

{name: "Andy", age: "10"},
{name: "Roy", age: "15"},
{name: "Henry", age: "17"}

我想在按年齡升序排序后檢索所有記錄。 我試過:

db.collection.find( { $query: {}, $orderby: { age : 1 } } ) //output without sorting
db.collection.find( { $query: {}, $search: { age : 1 } } ) //output without sorting
db.collection.find().sort("age": 1) //Error: find..sort is not a function

怎么解決,謝謝。

db.collection.find( { $query: {}, $orderby: { age : 1 } } ) 
db.collection.find( { $query: {}, $search: { age : 1 } } ) 
db.collection.find().sort( { age: 1 } )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM