说我有一个模式:
var UserSchema = new Schema({
firstName: {type: String},
lastName: {type: String},
friends: {type: [FriendSchema], ref: 'Friend'}
})
var FriendSchema = new Schema({
firstName: {type: String},
lastName: {type: String},
})
现在让我们说一个查询
db.User.find({}).populate({path: 'friends', $where: 'friend.lastName == $user.lastName'})
我知道上述查询不是有效的查询,但是我的问题是如何从填充查询的初始查找中访问用户对象的字段?这可能吗?