我正试图从这个结构中移除一个玩家。
{ "_id" : ObjectId( "51043d468ead0e0757000006" ),
"active" : true,
"created" : 1359232326,
"difficulty" : 0,
"map" : { "$ref" : "Map",
"$id" : ObjectId( "5103c0228ead0e3764000000" ),
"$db" : "fantasytd" },
"mode" : "coop",
"players" : [
{ "$ref" : "User",
"$id" : ObjectId( "50d83abf038054b560000000" ),
"$db" : "fantasytd" },
{ "$ref" : "User",
"$id" : ObjectId( "50d83abf038054b560000000" ),
"$db" : "fantasytd" },
{ "$ref" : "User",
"$id" : ObjectId( "50d83abf038054b560000000" ),
"$db" : "fantasytd" },
{ "$ref" : "User",
"$id" : ObjectId( "50d83abf038054b560000000" ),
"$db" : "fantasytd" } ],
"title" : "testgame" }
我试过了
$db->createQueryBuilder()
->update()
->field('id')->equals($gameId)
->field('players.$id')->equals($userId)
->pull('players.$.assets')
->getQuery()
->execute();
但它不会成功,遗憾的是 Doctrine MongoDB 的文档非常精简:/