对数组的$ lookup结果进行排序,但我不想对$ lookup的结果进行排序。 如何防止结果排序?
我有返回2d用户数组的api。 架构:
{
...
users: {
type: [
[
{
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
]
],
validate: {
validator: function(users) {
return users && users.length > 0;
},
message: 'At Least One User For Team Is Required'
}
},
....
}
聚合管道:
[
...
{
$unwind: '$users'
},
{
$lookup: {
from: User.collection.name,
localField: 'users',
foreignField: '_id',
as: 'users'
}
},
...
]