Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

store mongodb result in array?

Tags:

mongodb

meteor

Is it possible to store the result of a mongodb statement in array using jquery

I have like this

Polls_Coll.find({},{question:1});

I want all the question filed records to store in array some thing like

var arr[]=Polls_Coll.find({},{question:1});

I know above thing is wrong. I need something like that.

I need it for autocompletion. Now i'm taking source from one collection like this

 source:_(Product_Mobiles.find().fetch()).pluck("title")

I want data from multiple sources and store it in array

Thanks

like image 525
Sasikanth Avatar asked Jul 22 '26 05:07

Sasikanth


1 Answers

Using the mongo console you can do this with .toArray() like

var results = db.collection.find({}).toArray();

However, this might depend on the driver you are using... I guess the javascript driver has it as well.

If your problem is putting all the results from multiple sources into a single array: How to merge two arrays in Javascript and de-duplicate items

like image 182
joao Avatar answered Jul 23 '26 20:07

joao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!