javascript - Can't $push a new array to document in Meteor Collection -


i've been learning meteor 3 weeks, , still trying wrap head around updating/querying collections. i'm trying build slack clone, , created following collection 1 set of fixture documents:

conversations.insert({     channel: "#defaultchannel",     createdby: "coffeemeup",     timestamp: new date(),     followers: ["username1", "username2"],     entries: [     {       message: "this message #1",       postedtime: new date(),       author: "coffeemeup"     }] }); 

i'm trying insert document entries array using code below. not not work, throws "mutating [[prototype]] of object cause code run slowly..." error. i'd appreciate help!

conversations.update({     channel: "#defaultchannel" }, {     $push: {         entries: {             message: newmessage,             postedtime: new date(),             author: "coffeemeup"         }     } }); 

also, love hear suggestions on how better structure/design database build slack clone.

if want run update operations on clients, need use _id field. otherwise error:

error: not permitted. untrusted code may update documents id. [403]

as result, document first , subsequently use document's _id run update query.

for example:

var conversation = conversations.findone({     "channel": "#defaultchannel" });  conversations.update({     _id: conversation._id }, {     $push: {         entries: {             message: "newmessage",             postedtime: new date(),             author: "coffeemeup"         }     } }); 

here updated conversation document looks like:

{    "_id": "wgixgjgom6fk57mtn",    "channel": "#defaultchannel",    "createdby": "coffeemeup",    "timestamp": "2015-07-27t19:25:52.842z",    "followers": [       "username1",       "username2"    ],    "entries": [       {          "message": "this message #1",          "postedtime": "2015-07-27t19:25:52.842z",          "author": "coffeemeup"       },       {          "message": "newmessage",          "postedtime": "2015-07-27t19:27:54.930z",          "author": "coffeemeup"       }    ] } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -