0

I have a document structured as so: (simplified to get to the point)

{
    "_id" : "WRcx25SxCxQHA29Be",
    "whichUser" : "KKCjvgbQKm7ahfNd5",
    "textSpans" : [ { 
        "_id" : "ExxMXBc3T6dtDZbRC",
        "textValue" : "the special tonight is chicken" 
    },
    {
        "_id" : "4kPWbEH3GhppqrEYt",
        "textValue" : "more text"
    } 
    ]
} 

given a particular text-spans "_id" field, how can I perform an update?

ChosenCards.update({_id:myChosenCardId}, {$set: { ??

(note, this is not a question about how to use explicit array indices.)

Which Mongo options will allow me to update a field in a subdocument given that sub-documents _id?

Faysal Ahmed
  • 1,592
  • 13
  • 25
  • So `.update{ "_id": "WRcx25SxCxQHA29Be", "textSpans._id": "4kPWbEH3GhppqrEYt" },{ "$set": { "textSpans.$.textValue": "overwriting text" } })` which is the translation in your case to what the answers in the linked question are telling you. – Blakes Seven Mar 08 '16 at 11:12
  • yes, Blakes Seven, that is exactly what I was seeking! i'm not sure if this is duplicate, however, as I see new material about multiple-selectors in your answer, which I never saw in the other answer, which DOES address the secondary part of how to access the particular element. thank you. how do I mark your comment as an answer and close this? – vectorselector Mar 08 '16 at 11:19
  • rather, the other question does not explicitly address the ability to use multiple terms in the selector, and rather focuses on the options required to access the subdocuments field. i would say that unless this site wishes to clarify the first question explicitly, leave this question up for now and then feel free to merge at some point. thank you, Blakes Seven – vectorselector Mar 08 '16 at 11:26
  • Believe me, I'm completely sure it's a duplicate. You don't **need** both conditions in the "query" portion, but just the one that identifies the array element. If that is not completely "unique" across documents, then you use something else to select the "document" that contains it, unless you possibly want to modify other documents, with possible matches on the same content in their own arrays. That's just logic. The important thing here is the marked duplicate, and not multiple answers saying the same thing. – Blakes Seven Mar 08 '16 at 11:27

0 Answers0