mongodb - how to manipulate returned mongo collections / cursors in javascript (meteor.js)? -
in working meteor.js , mongo use find({some arguments}) , find({some arguments}).fetch() return cursors , array of matching documents respectively.
what real difference between two? (when use 1 versus other?)
what proper way manipulate/iterate on these type of returned objects?
e.g. have collection has many documents each title field.
my goal array of title fields' values e.g. [doc1title,doc2title,doc3title]
i did this:
var i, listtitles, names, _i, _len; names = entries.find({}).fetch(); listtitles = []; (_i = 0, _len = names.length; _i < _len; _i++) { = names[_i]; listtitles.push(i.title); } or equivalent in coffeescript
names = entries.find({}).fetch() listtitles = [] in names listtitles.push(i.title) which works, have no idea if proper way or semi sane way.
your first question has been asked before - see this post. short answer want use cursor returned find unless need of data @ once in order manipulate before sending template.
your coffeescript rewritten as:
titles = (entry.title entry in entries.find().fetch()) if using underscore, written as:
titles = _.pluck entries.find().fetch(), 'title'
Comments
Post a Comment