I have the following Mongo DB document structure:
{
_id: channelId,
title: channelTitle,
pubDate: channelPubdate,
items:
[
{
title: newsTitle,
desc: newsDescription,
link: newsLink,
pubDate: Date,
clicks: 0
},
{/*One more*/},
{/*...*/}
]
}
I have troubles incrementing the "clicks" field in the Collection (updating the field of a document embedded in an array).
I tried this in an event handler (client):
News.update({ _id : Session.get("channelId"), "items.link" : this.link },
{ $inc: { "items.clicks": 1 } }
);
But it gives an error: Uncaught Error: Not permitted. Untrusted code may only update documents by ID. [403]
I then tried via a server method:
Meteor.methods({
incClicks: function(id, news)
{
News.update({ _id : id, "items.link" : news.link },
{ $inc : { "items.clicks": 1 } }
);
}
});
Yet, another exception: Exception while invoking method 'incClicks' MongoError: can't append to array using string field name: clicks
What would be a correct Mongo request for this action?