Your control flow is wrong. I've added a few console.log in your code
below. Output should be:
BEFORE FIND
BEFORE DB FOREACH
AFTER FIND
DB FOREACH CALLBACK
AFTER CURRDATA ASSIGNMENT
This should explain why currData is still undefined after the find call.
Bruno
On Wednesday, February 4, 2015 at 11:06:13 AM UTC+1, Mateusz Woziu wrote:
>
> Hi there, I have two tasks to do:
> 1. Mongo Call ---> simple find with query
> 2. Searching in the result of Mongo find with forEach and making another
> request to different collection..
> 3. res.send changes which have been done in forEach loop.
>
> For now it looks like that:
>
> db.collection.find().sort({ "rank": order }).skip(pagenumber).limit(5,
> function (err, result) {
>
currData = result;
>
console.log("AFTER CURRDATA ASSIGNMENT");
>
> });
>
console.log("BEFORE FIND");
> find(currData);
>
console.log("AFTER FIND");
> res.send(currData);
>
>
> and find is a function() like :
>
> function find(db) {
>
console.log("BEFORE DB FOREACH");
> db.forEach(function (prevResult) {
>
console.log("DB FOREACH CALLBACK");
> db.collectionOther.find({ MID: commId }, function (error, result) {
> result.forEach(function (r) {
> some calculations;
> if (condition) {
> prevResult= Calculations;
> }
> });
> });
> });
>
>
> I tired to do it whit process.nextTick but failed. Could someone help mi
> to make the calls be done after each other and not at the same time?
>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/22cb5cf5-1968-4639-be22-a3aa66ec4aa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.