I am very new to MongoDB and Mongoose and seem to have found myself needing a fairly complex query right off the bat. My schema is below.
const gameSchema = new mongoose.Schema({
_winnerId: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'User',
},
_loserId: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'User',
},
winnerWords: [String],
loserWords: [String],
});
I am trying to get the win/loss ratio for a given user id. Somehow, I need to count up both how many times the userid appears as the _winnerId and how many times the userid appears as the _loserId. Can this be done with a single query?