0

我有以下猫鼬模式和模型:

//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);

我的数据库中已经有一个包含四个玩家的游戏板。现在我正在尝试使用以下命令更新数据库中的特定播放器:

GameBoard.update({_id: game._id, "mPlayers.mUsername": updatedPlayer.mUsername}, {$set: {"mPlayers.$": updatedPlayer}}).exec();

但这似乎不起作用,但我没有收到错误=/。我试图用相同的参数进行查找,这就像一个魅力。有人可以指出我做错了什么吗?

4

1 回答 1

0

我尝试了一些不同的东西,看起来猫鼬不喜欢 $. 当我在做“mPlayers.1”时,它就像一个魅力:)

于 2013-03-17T18:28:46.000 回答