javascript - How to concatenate (or union) the results of find() from two mongodb collections in Meteor JS? -


how can concatenate (or merge or union) results of find() 2 mongodb collections in meteor js? preferably want join them single cursor object, fetching , converting array acceptable. should use instead of union in following code? note: don't need remove repeated elements. concatenation enough.

alllocations: function(){    location_set_1 = tablea.find({'loc':{$exists:1}},{loc:1,limit:300});    location_set_2 = tableb.find({'loc':{$exists:1}},{loc:1,limit:300});    combined_location_set = ??union??(location_set_1,location_set_2)    return combined_location_set; } 

a (n incomplete) solution may following return array. instead need return cursor object "helper" in meteor:

a=tablea.find() b=tableb.find() c=_.extend({},a.fetch(),b.fetch()) // c=[].concat(a.fetch()).concat(b.fetch()); return c; 

something ?

alllocations: function(){    var location_set_1 = tablea.find({'loc':{$exists:1}},{loc:1,limit:300}).fetch();    var location_set_2 = tableb.find({'loc':{$exists:1}},{loc:1,limit:300}).fetch();    var result = [];    (i = location_set_1.length - 1; >= 0; --) {        result.push(location_set_1[i]);    }    (i = location_set_2.length - 1; >= 0; --) {        result.push(location_set_2[i]);    }    return result; } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -