hi guys, had a question, how to make method update, but without inserting parameter id (_id), i just need to update all the colomn i don’t need to be specific which column with what id that must be updated.
If I’m reading this right, you need some sort of selector in the update()
to indicate which documents are to be updated. This is commonly the document’s _id
, but can also be a mongo selector if you don’t have the _id
or want to update multiple documents.
I can’t quite tell what’s going on in your code, but I hope this helps.
i’m bad in this meteor programming, the way i need to update a data in mongodb, i must use a method which confusing me, i’m used to mysql not nosql. just how to update field lock from table stories using meteor method? data typle true/false (boolean)
If you’re used to sql, you can more or less think of collections as tables, and documents as rows. There’s no enforcement of a schema by default, but it’s quite common to use the same set of fields for all documents in a collection. All documents also have an _id
field, which uniquely identifies a document in a collection, and which is often used as a foreign key. You can read more about collections and how they work here:
Since you’re trying to update the lock
field on all the documents in a collection, I suggest changing your method to look something like this:
Meteor.methods({
ToggleMenuItem: function(currentState) {
// prevent nosql injection
check(currentState, Boolean);
StoryGroups.update(
{}, // select all documents in the collection
{$set: {lock: !currentState}},
{multi: true} // allow multiple documents to be updated at once
);
},
});
You may also find the Methods article in the Guide helpful to read through: