// 我想首先出現帶有 isFeatured:"true" 的檔案
{ "_id": "625c13ea5c5d3f49f152783b",
"name": "helmet 1",
"description": "gold",
"category": [
"helmet"
],
"price": "25000",
"stock": 25,
"user": "",
"isFeatured": true // with this property to come first and "isFeatured:false" later
}
uj5u.com熱心網友回復:
您可以呼叫sort游標以按降序myCollection對欄位中的檔案進行排序。isFeatured
db.myCollection.find().sort({ isFeatured: -1 })
或者關于聚合管道查詢
db.myCollection.aggregate([{ $sort: { isFeatured: -1 } }])
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/465224.html
標籤:mongodb
