有问题:
userMoments:
userId: {
type: String,
required: true
},
momentId : {
type : String,
required : true
},
pay : {
type : Number
},
momentActive : {
type : Boolean,
default : false
}
和时刻:
name: {
type: String,
required: true
},
img : {
type : String
}
我需要从moments
集合中获取所有不在集合userMoments
中的内容以及一些userId
答案 0 :(得分:0)
为实现这一点,我建议以下示例:
(1)获取与momentId
相关的userMoments
存储的所有userId
(2)获取与我们获得的moments
无关的所有momentId
// Get all momentId
UserMoments.find({
$in: arrayThatContainsUserIds,
}, 'momentId')
// Make every momentId unique
.distinct('momentId')
.exec()
// get all moments that do not refer to ids we got before
.then((ret) => find({
$nin: Array.from(ret, x => x.momentId),
}))
.then((ret) => {
// Here you have your moments
})
.catch(err => {});