I have a Meteor method that I call from the client, which in turn updates all fields in a single document. In the last line of code below I try to immediately run the same update on the client to get the immediate side effects (it assumes the update will go through). The trouble is I get:
update failed: Access denied. In a restricted collection you can only update documents, not replace them. Use a Mongo update operator, such as '$set'
when trying to do that. I don't want to update a single field, I want to update the whole document. Is there a way to do this properly?
entry = {
title: title
text: text
tags: entry.tags
mode: $('#mode').val()
file_ids: entry.file_ids
}
eid = Session.get('entryId')
entry._id = eid if eid
context = Session.get('context')
Meteor.call('saveEntry', title, entry, context)
Entries.update({_id: entry._id}, entry)
Do something like:
A typical update request is on the form:
From the Mongodb documentation, about updating with a regular key:value object:
and about updating specific fields, using
$set
,$inc
etc.:And additionally, as I can understand, from your error message Meteor don't allow replacing whole documents entirely, from the client side. So an option is to use the
$set
operator and set all the values, which in this case is the whole document itself. You may typically skip adding the_id
key to your document before passing it to the$set
operator.