javascript - Return contents of one field (an array) from Mongodb document in Meteor -


i working in meteor , trying retrieve contents of 1 field in mongodb document. particular field array. i've read mongo docs , several related questions, projection isn't working. have:

user adds array using following form:

template.one.events({     'submit form': function(e) {         e.preventdefault();         var currentid = this._id         var oneproperties = {             selections: $(e.target).find('[name=selection]').val()         };         charts.update(currentid, ($addtoset: selections}, function() {});     } }); 

resulting document:

{     "_id": "some id",     "selections": ["a","b"] } 

refer array in helper different template access documents different collection.

template.two.helpers({     comps: function() {         var selected = charts.findone({_id:this._id}, {selections:1, _id:0});         return companies.find({ticker: {$in: selected}});     } }); 

when run charts.findone query above directly in console, returns entire document, no limitations.

if replace charts.findone({_id:this._id}, {selections:1, _id:0}); ["a","b"], else works perfectly. know projection itself. can't tell if query return need array, need, or name selections: well.

any thoughts appreciated.

try accessing selections field of document, should give array directly, not entire document:

var selected = charts.findone({_id:this._id}, {selections:1, _id:0}); 

would give { "selections": ["a","b"] }

but

var selected = charts.findone({_id:this._id}, {selections:1, _id:0}).selected; 

will give needed array

["a","b"] 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -