in a project I just joined, they have 2 schemas: players et users, a player reference 2 users with objectIds.
const player = new Schema({
name: string,
best: {
friendId: { type: Schema.Types.ObjectId, ref: 'User' }
},
worst: {
enemyId: { type: Schema.Types.ObjectId, ref: 'User' }
}
})
const user = new Schema({
name: string
})
We would like to be able to search the players by just entering a name but it can be the name of the player or the name of any user referenced. Can this be done with mongoose using a single query ?