I'm trying to find and update an element within an array in a mongodb collection in a meteor app.
Every element in the array is an object that has an "_id" attribute, so I'm using mongo's '$' pointer:
Collection.update({things._id: currentThingId},{$set: {things.$.value: aGivenValue}});
However, it keeps throwing me an "Unexpected ." exception, pointing to the line where I use "things**.**_id". I followed mongodb documentation, so any chance meteor has some limitatiob with this mongo functionality?
You need to enclose the field with quotes when using the dot notation to access an element of an array by the zero-based index position, bearing in mind that the positional $
operator limits the contents of an array from the query results to contain only the first element matching the query document. Thus your final update query should look like:
Collection.update({"things._id": currentThingId},{$set: {"things.$.value": aGivenValue}});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加