I tried to search for the answer all the way, but I can not get it to work. I am using Meteor with Cordova to create a mobile application.
I want to add an attribute to my Users collection (the one that Meteor creates when I logged in). i.e. For example, I want to add {currentHotel: "Something"} to my db.Users collection.
I'm trying to do it right, publish - Sign the path. Using Meteor.methods has been cited for not being good for real-time applications. In any case, I want to understand how to update the Users collection using Publish-Subscribe.
//On the server, I did Meteor.publish("userData", function () { return Meteor.users.find({_id: this.userId}, {fields:{services: 1, currentHotel: 1}}); });
So, the currentHotel field should be available on the client side. Now update the currentHotel field:
//On the client I do Meteor.subscribe('userData'); var user = Meteor.users.findOne({"_id": Meteor.userId()}); Meteor.users.update({_id: user._id}, {$set:{currentHotel:'something'}}); //I tried this too //Meteor.users.update({ _id: Meteor.userId() }, {$set: });
In the browser console, I see "currentHotel" and "services" just fine, which means that working with publish-subscribe works. However, I cannot update the currentHotel. I get Access Denied. Why is this?
Also, if the "currentHotel" property does not exist in the collection at all, how can I add it using a similar subscription publication? Can I publish a property that is not there and allow the client to subscribe and add this property?
I mentioned the docs Meteor, this , and this , but it still can't seem like it works !: - (
Thanks in advance!
collections mongodb meteor publish-subscribe meteor-accounts
Nilay panchal
source share