Victor Eliot
Victor Eliot

Reputation: 87

Meteor.js update only one parameter instead of whole collection

I'm trying to mark message as readed using code below :

Template.FullMessage.onRendered(function () {
            var id = FlowRouter.getParam('id');
            Messages.update(id, {$set: {readed: true} });
});

Collection is :

"_id": "YMxYn9NodPeZqFP83",
  "whatAbout": "adsfadsfasdf",
  "message": "sdfadsfadfadsfasdfasdf",
  "recipientId": "9ewiF8JTNp77Pmijw",
  "author": "9ewiF8JTNp77Pmijw",
  "createdAt": "2016-05-09T08:37:52.282Z",
  "owner": "seofilms",
  "readed": false
}

I expected that column "readed":"false" will be replaced with "readed":true,

but instead of it, everything in here is changing, including owner. So for instance if I will open message with user test, I will change also the owner of this message.

Why does it happens ?

Is it possible to prevent sending whole object and change it only with ID?

Thank you for any ideas.

Upvotes: 1

Views: 50

Answers (1)

smoksnes
smoksnes

Reputation: 10851

Try this:

Messages.update({_id: id}, {$set: {readed: true} });

It should also work with only id, as you're already doing. Is there any other code that's writing to the same collection? Try to run it in console and check if it's still updating all the properties.

Upvotes: 1

Related Questions