I… admittedly asked a grossly similar question to this quite recently, but am still confused on something not-quite-exactly-the-same, this time involving the positional operator, probably. Terribly grateful for any help I can get, as always.
I have a collection called “Groups” that looks approximately like this:
If I wanted to change the permissions field of just one of these subdocuments – the second one – I could update this using the below – this much works for me:
What I can’t figure out is how I can retrieve the data in the permission field of that second document only – specifically I need to return it in a meteor method. I tried an analogous construction involving ‘fields’ but had no luck. Is the positional operator the wrong way to approach this?
Okay, this makes sense, but unfortunately in my actual case, I need to be able to find a single field in a subdocument of a specific document; I can’t have cases from other documents that match on the other field. So I tried this:
…which I seems to match your example except for the fact that I’m specifying the _id of the parent document, but gave me errors. With pretty() at the end, I got
"Exception while invoking method ‘MethodName’ TypeError: Object [object Object] has no method ‘pretty’".
Sorry I wasn’t more clear initially, but how can I return just one field of one embedded document in one, specified parent document?
I’m still new to Meteor, and I must say, figuring out precisely the syntax needed to return data from documents (especially with subdocuments in the mix) has been the part been slowest to get a handle on, but one more case I grok now – thank you so much for the help.