Reputation: 580
I'm currently developing a multiplayer card game with a node.js + mongodb backend. I want users to be able to join games so I'm implementing a queue function. In this queue function I want to be able to get a single game from mongodb that is not started, not locked and doesn't contain the player in the queue.
Example of my mongodb game document:
{
"_id": {
"$oid": "512cccf9e4b09000a6f1f079"
},
"mChanceTaken": false,
"mCurrentPlayer": 0,
"mCurrentPlayerName": "-",
"mDeck": [
{
"mValue": 13,
"mSuit": "HEARTS"
},
{
"mValue": 13,
"mSuit": "SPADES"
},
{
"mValue": 3,
"mSuit": "SPADES"
},
{
"mValue": 10,
"mSuit": "SPADES"
},
{
"mValue": 11,
"mSuit": "CLUBS"
},
{
"mValue": 3,
"mSuit": "HEARTS"
},
{
"mValue": 7,
"mSuit": "DIAMONDS"
},
{
"mValue": 9,
"mSuit": "SPADES"
},
{
"mValue": 8,
"mSuit": "HEARTS"
}
],
"mFinished": false,
"mLocked": false,
"mNumberOfPlayers": 4,
"mPlayers": [
{
"mPlayerId": "512bd9a1e4b09000a6f1f073",
"mUsername": "user2",
"mPosition": 0,
"mSwitching": true,
"mFaceUp": [],
"mFaceDown": [],
"mHand": []
},
{
"mPlayerId": "512bcb3be4b09000a6f1f06b",
"mUsername": "user1",
"mPosition": 0,
"mSwitching": true,
"mFaceUp": [],
"mFaceDown": [],
"mHand": []
}
],
"mRoundLength": 60,
"mStarted": false,
"mSwitching": false
}
My current query looks like this:
GameBoard.findOneAndUpdate({mStarted: false, mLocked: false, mPlayers: {$not: {mPlayerId: player.mPlayerId}}}, {mLocked: true}, function (err, gameBoard) {
I think I should use the $not operator but I can not figure out how to use it in my use case. please someone help me!
Upvotes: 0
Views: 667