Hi,
I need to traverse an array, and compare value of the array with the values
in mongodb. However, I want to match a pattern starting with array value
and not the exact value. For example: arr[0] is "John", I want to find all
values in mongodb users table whose name start with "John". For this, I can
write a query as "collection.find({name*:/^John/*})". However, if I want to
do this query in a loop for all the elements of array "arr", how can that
be achieved?
var arr=[];
arr=["John","Rahel","George"];
MongoClient.connect('mongodb://127.0.0.1:27017/MyDatabase', function(err,
db){
var collection = db.collection('users'); // Assume that numbers is a table
in mongodb
for(var i=0;i<arr.length;i++)
{
collection.find({name*:/^arg[i]/*}).toArray(function(err, result)
{
//do something
}
}
}
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.