We want to query a collection using two fields (ids) to find a specific conversation that has userOne and or userTwo with same id number like we want to find all the conversations that has 57e334af0e5fcc9e8e800177 id in userOne or userTwo
Mongoose Schema
userOne: {type: mongoose.Schema.Types.ObjectId, ref:'users'},
userTwo: {type: mongoose.Schema.Types.ObjectId, ref:'users'},
created_at: {type: Date, default: Date.now}
Query that we tried.
db.getCollection('conversations').find({
$or : [{userOne: "57e334af0e5fcc9e8e800177"}],
$or : [{userTwo: "57e334af0e5fcc9e8e800177"}]
})
Sample Conversation Object
_id: "57eae04c4efbb25487a00293"
created_at: "2016-09-27T21:10:36.236Z"
userOne: "57e334c00e5fcc9e8e800178"
userTwo: "57e334af0e5fcc9e8e800177"