0
我们想要使用两个字段(id)查询集合来查找具有userOne和/或userTwo的具有相同id号的特定对话,就像我们想要查找在userOne或userTwo中具有57e334af0e5fcc9e8e800177 id的所有对话一样MongoDB条件查询
,我们试图猫鼬架构
userOne: {type: mongoose.Schema.Types.ObjectId, ref:'users'},
userTwo: {type: mongoose.Schema.Types.ObjectId, ref:'users'},
created_at: {type: Date, default: Date.now}
查询。
db.getCollection('conversations').find({
$or : [{userOne: "57e334af0e5fcc9e8e800177"}],
$or : [{userTwo: "57e334af0e5fcc9e8e800177"}]
})
样品谈话对象
_id: "57eae04c4efbb25487a00293"
created_at: "2016-09-27T21:10:36.236Z"
userOne: "57e334c00e5fcc9e8e800178"
userTwo: "57e334af0e5fcc9e8e800177"
谢谢你的作品我的开发服务器上,但是当我用MongoDB的图集连接它不是拉出数据,谢谢你的帮助,我会发现错误 –