node.js - Querying multiple collections in MongoDB scoping issue -


I want to query two separate collections by using MongoJS (node.js mongodb wrapper) to create an array of objects I am trying to present myself with my views using EJS.

The issue I have raised is doing it with scoping function getTeamMembers (projectID) {var member = []; // & lt; - Instant the array of objects. I want to return the projects. Fondon ({_id: mongojs.ObjectId (projectID)}, function (error, result) / // and click on the members array var team = P. = result.team; // <- It's a (var i = 0; i & lt; team.length; i ++) one for objects The array is {members [i] = {}; member [i] .accountID = team [i] .accountID; subscriber [i] .status = team [i] .status; accounting.fundon ({_id: mongojs.ObjectId ( Team [i] .accountID)}, work (error, d) Octor) {/// error occurs in the following line: /// 'Property name can not be set for undefined member' [i] .name = doc.name;});} response.send (members) ;}); }

I am convinced that I am providing the members [] array immediately in the right place to make it available to any child's work, But I'm still getting this error:

Type error: property can not set 'name' to undefined.

< Div class = "post-text" itemprop = "text">

You need to create an area that takes the current code to i , why F your findOne () callback to be executed, ending loop is already to be long and i = team.length .

This

this: You are sending the feedback even before filling any name.

 for  (var i = 0; i   

becomes:

  var async = require ('async'); // .... async.each (Team, Function (Team Eatm, Callback) {var Members = {Account ID: Team Item Account, Status: Team ITEM.Stats, Name: ''}; Member.Pash ( Member); FindOne ({_id: mongojs.ObjectId (member.accountID)}, function (error, doctor) {if (error) callback (error); other {member.name = doc.name; callback ();}} );}, Function (mistake) {if (response) response.send (500, err.toString ()); else response.send (members);});    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -