7

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

2 Answers 2

11

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

Sign up to request clarification or add additional context in comments.

1 Comment

Get the results from each source and then concatenate the arrays into a single array.
2

You could merge the two arrays if thats what you mean:

var results = collection.find({}).fetch();
var results2 = collection2.find({}).fetch();

results = results.concat(results2);

Then you can do pluck

_(results).pluck("title");

Also you can't use db. in Meteor you have to use the name of the collection varaible you defined with new Meteor.Collection

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.