I have a query which return me the records or messages for a certain scenario:
const [messages, messageCount] = await Promise.all([
MessageModel.find(params).select(filterObject).limit(ctx.query.limit).skip(ctx.paginate.skip)
.sort('-sex -age')
.lean(),
MessageModel.countDocuments(params),
]);
Is there any way to get the records first which matches an object id, and then rest of the records?
Result
{
_id:abc0aa8573bfa917b152cdbc
isPrivate:false
message:"My name is stark"
gender:"unisex"
age: "19"
createdBy:abcff9ef71fa048cea3c8a97
}
{
_id:abc0aa8573bfa917b152cdbc
isPrivate:false
message:"My name is james"
gender:"unisex"
age: "20"
createdBy:defff9ef71fa048cea3c8a97
}
{
_id:abc0aa8573bfa917b152cdbc
isPrivate:false
message:"My name is harry"
gender:"unisex"
age: "20"
createdBy:defff9ef71fa048cea3c8a97
}
{
_id:abc0aa8573bfa917b152cdbc
isPrivate:false
message:"My name is max"
gender:"unisex"
age: "20"
createdBy:abcff9ef71fa048cea3c8a97
}
Now I want those messages that was created by the abc... first. All those records that match a certain id would come first and then rest of the records would remain the same
{
_id:abc0aa8573bfa917b152cdbc
isPrivate:false
message:"My name is stark"
gender:"unisex"
age: "19"
createdBy:abcff9ef71fa048cea3c8a97
}
{
_id:abc0aa8573bfa917b152cdbc
isPrivate:false
message:"My name is max"
gender:"unisex"
age: "20"
createdBy:abcff9ef71fa048cea3c8a97
}
{
_id:abc0aa8573bfa917b152cdbc
isPrivate:false
message:"My name is james"
gender:"unisex"
age: "20"
createdBy:defff9ef71fa048cea3c8a97
}
{
_id:abc0aa8573bfa917b152cdbc
isPrivate:false
message:"My name is harry"
gender:"unisex"
age: "20"
createdBy:defff9ef71fa048cea3c8a97
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…