次のステートメントでスコアを追加できます:
db.userscores.update(
{ "name": "John Doe", "levels.level": 1 },
{ "$push": { "levels.$.hiscores": 75 } } )
これは 配列要素がドキュメントである場合にのみサポートされるため、配列を並べ替えます。
MongoDB 2.6では、ドキュメント以外の配列にも並べ替えを使用できます。
db.userscores.update(
{ "name": "John Doe", "levels.level": 1 },
{ "$push": { "levels.$.hiscores": { $each: [ 75 ], $sort: -1, $slice: 3 } } } )