righe Sto tentando di eseguire un aggiornamento mongodb su ciascun campo in una matrice di record.
Uno schema esempio è qui sotto:
{
"_id" : ObjectId("508710f16dc636ec07000022"),
"summary" : "",
"uid" : "ABCDEF",
"username" : "bigcheese",
"name" : "Name of this document",
"status_id" : 0,
"rows" : [
{
"score" : 12,
"status_id" : 0,
"uid" : 1
},
{
"score" : 51,
"status_id" : 0,
"uid" : 2
}
]
}
Finora sono stato in grado di eseguire singoli aggiornamenti in questo modo:
db.mycollection.update({"uid":"ABCDEF","rows.uid":1}, {$set:{"rows.$.status_id":1}},false,false)
Tuttavia, sto lottando su come eseguire un aggiornamento che aggiornerà tutti i record dell'array su un status_id
di 1 (per esempio).
Qui di seguito è come mi immagino che dovrebbe funzionare:
db.mycollection.update({"uid":"ABCDEF"}, {$set:{"rows.$.status_id":1}},false,true)
Tuttavia ottengo l'errore:
can't append to array using string field name [$]
Ho cercato per un po 'senza fortuna. Qualche indicazione?
OK, grazie. Credo che allora avrò attraversato l'array. – HGPB