javascript - Retrieve value as string from an array in Meteor -
how possible retrieve particular element in array string? have populated field called 'list' consist of document id's posts collection.
the postid's inserted in next manner within method:
var postid = //code retrieving post id meteor.users.update( this.userid, { $addtoset: { 'profile.list': postid}});
now, retrieve first postid value find post document.
var postid = meteor.user().profile.list; posts.update( {_id: postid}, { $addtoset: {'message': sometext}});
the update not work appears in console log retrieving object [ 'svnjazwnfw8fpobjv' ]
- not string. if manually insert postid value enclosed speech marks, work.
how can target specific position of 'list' field , utilize value perform update?
if want update individual postid::
// index position in list want update (0 first one) posts.update( {_id: postid[index]}, { $addtoset: {'message': sometext}});
if wanted update whole lot:
posts.update( {_id: { $in: postid }}, { $addtoset: {'message': sometext}});
javascript mongodb meteor
No comments:
Post a Comment