Updating array element in a collection in Meteor

Maboo

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?

chridam

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]

編集
0

コメントを追加

0

関連記事

分類Dev

Updating already published collection in Meteor

分類Dev

Meteor.js collection: new record not updating in bootstrap ui popover

分類Dev

Meteor.js - automatically updating one Mongo collection when another mongo collection changes?

分類Dev

Draw each element of array in new row with DataTables (Meteor Tabular)

分類Dev

Meteor Collection.allow

分類Dev

Meteor: observe a collection with reactiveVar

分類Dev

Meteor.CollectionおよびMeteor.Collection.Cursor

分類Dev

inserting value in meteor collection document

分類Dev

UI Element is not updating

分類Dev

Object in array is not updating in JavaScript

分類Dev

Insert data in collection at Meteor's startup

分類Dev

Meteor drop collection after every query

分類Dev

Meteor: "TypeError: undefined is not an object" when using collection

分類Dev

How to query username from userId in a collection in Meteor?

分類Dev

Subscribe meteor collection through a handlebars helper

分類Dev

How to get the highest _id for the collection in meteor?

分類Dev

meteor.js - set controller to access collection

分類Dev

Wpf Observable collection and DataGrid not updating changes

分類Dev

Meteor - How to update a document in an array

分類Dev

WPF Binding GridView to Element in collection

分類Dev

Find the same element in MongoDB Collection

分類Dev

updating a JSON array in AWS dynamoDB

分類Dev

Angular 2 Updating Array object

分類Dev

Updating state array length in React

分類Dev

useState setter method not updating array

分類Dev

laravel updating value in session array

分類Dev

Updating an object in an array if the object exists

分類Dev

Change of element in column not updating in data frame

分類Dev

How can I use collection.find as a result of a meteor method?

Related 関連記事

  1. 1

    Updating already published collection in Meteor

  2. 2

    Meteor.js collection: new record not updating in bootstrap ui popover

  3. 3

    Meteor.js - automatically updating one Mongo collection when another mongo collection changes?

  4. 4

    Draw each element of array in new row with DataTables (Meteor Tabular)

  5. 5

    Meteor Collection.allow

  6. 6

    Meteor: observe a collection with reactiveVar

  7. 7

    Meteor.CollectionおよびMeteor.Collection.Cursor

  8. 8

    inserting value in meteor collection document

  9. 9

    UI Element is not updating

  10. 10

    Object in array is not updating in JavaScript

  11. 11

    Insert data in collection at Meteor's startup

  12. 12

    Meteor drop collection after every query

  13. 13

    Meteor: "TypeError: undefined is not an object" when using collection

  14. 14

    How to query username from userId in a collection in Meteor?

  15. 15

    Subscribe meteor collection through a handlebars helper

  16. 16

    How to get the highest _id for the collection in meteor?

  17. 17

    meteor.js - set controller to access collection

  18. 18

    Wpf Observable collection and DataGrid not updating changes

  19. 19

    Meteor - How to update a document in an array

  20. 20

    WPF Binding GridView to Element in collection

  21. 21

    Find the same element in MongoDB Collection

  22. 22

    updating a JSON array in AWS dynamoDB

  23. 23

    Angular 2 Updating Array object

  24. 24

    Updating state array length in React

  25. 25

    useState setter method not updating array

  26. 26

    laravel updating value in session array

  27. 27

    Updating an object in an array if the object exists

  28. 28

    Change of element in column not updating in data frame

  29. 29

    How can I use collection.find as a result of a meteor method?

ホットタグ

アーカイブ