I have the following Mongoose schema and model:
//GameBoards
var gameBoardSchema = mongoose.Schema({
mCurrentPlayer: Number,
mCurrentPlayerName: String,
mStarted: Boolean,
mSwitching: Boolean,
mFinished: Boolean,
mPlayers: [{mPlayerId: String, mUsername: String, mHand: [{mValue: Number, mSuit: String}], mFaceDown: [{mValue: Number, mSuit: String}], mFaceUp: [{mValue: Number, mSuit: String}], mPosition: Number, mSwitching: Boolean}],
mDeck: [{mValue: Number, mSuit: String}],
mPile: [{mValue: Number, mSuit: String}],
mStartedAt: {type: Date},
mLastUpdate: {type: Date},
mChanceTaken: Boolean,
mRoundLenght: Number,
mNumberOfPlayers: Number,
mLocked: Boolean
});
var GameBoard = mongoose.model('gameBoard', gameBoardSchema);
I already have a gameBoard in my database with four players. Now I'm trying to update a specific player in the database with the following command:
GameBoard.update({_id: game._id, "mPlayers.mUsername": updatedPlayer.mUsername}, {$set: {"mPlayers.$": updatedPlayer}}).exec();
But this does not seem to be working, but I get no error =/. I have tried to do a find with the same parameters and that works like a charm. Can someone pin point what I'm doing wrong?
I tried some different things and it seems like mongoose doesn't like the $. When I'm doing "mPlayers.1" it works like a charm :)