I'm looking to add a new field (array that will be populated with $push in the future) to the current document but am getting the error update failed: MongoError: Cannot apply $push/$pushAll modifier to non-array
I'm working on the Meteor.users collection.
The code ran was:
var user = Meteor.userId();
Meteor.users.update({_id:user}, {$set: {"newfield": ["some data"]}});
This happens because you're not supposed to change the root fields of the user object. From the docs:
By default, the current user's
username
,emails
andprofile
are published to the client. You can publish additional fields with [...]
So you can
Meteor.users.update(user, {$set: {"profile.newfield": ["some data"]}});
Note though that you should limit what you store in profile
.