0

Given the following MongoDB example collection ("schools"), how do you remove student "111" from all clubs?

[
  {
    "name": "P.S. 321",
    "structure": {
      "principal": "Fibber McGee",
      "vicePrincipal": "Molly McGee",
      "clubs": [
        {
          "name": "Chess",
          "students": [
            ObjectId("111"),
            ObjectId("222"),
            ObjectId("333")
          ]
        },
        {
          "name": "Cricket",
          "students": [
            ObjectId("111"),
            ObjectId("444")
          ]
        }
      ]
    }
  },
  ...
]

I'm hoping there's some way other than using cursors to loop over every school, then every club, then every student ID in the club...

4

1 に答える 1

0

MongoDB には、配列内の配列 (配列内 ...) に対する優れたサポートはありません。私が見る最も簡単な解決策は、ドキュメント全体をアプリに読み込み、そこで変更してから保存することです。もちろん、この方法では操作はアトミックではありませんが、アプリにとっては問題ない場合があります。

于 2012-10-21T10:26:07.560 に答える