mongodb - Bug on line 52 of my javascript code and i can't figure it out -


i'm using below javascript code in appery.io app. keep getting error states following:

6/25/2014 9:37:35 pm:   script all_users_data: typeerror: cannot read property '_id' of undefined ( @ 52 : 33 ) -> if (all_photo[i].the_user._id == id) { 

please me identify bug. i'm attempting pull data 3 collections, sync them _id 'users' collection , output user profile type information.

var all_users = eval(databaseuser.query('52895ecce4b056c5e94f34f9')); var all_profiles = eval(collection.query('52895ecce4b056c5e94f34f9', 'profile')); var all_status = eval(collection.query('52895ecce4b056c5e94f34f9', 'status')); var all_photo = eval(collection.query('52895ecce4b056c5e94f34f9', 'photo'));  // loop on users (var i=0;i<all_users.length;i++) {     // call function search user profile , add first name current user            item     getprofile(all_users[i]._id, all_users[i]);     // call function search user status , add last status current user   item       getstatus(all_users[i]._id, all_users[i]);     getphoto(all_users[i]._id, all_users[i]); }  // function user item , user id , find user profile id , update function getprofile(id,curuser) {     var found = false;     (var = 0; < all_profiles.length; i++) {         // if cur user id = profile id assign profile name user         if (all_profiles[i].the_user._id == id)         {             curuser.firstname = all_profiles[i].firstname;             curuser.university = all_profiles[i].university ;              found = true;         }     }     if (!found)     {         curuser.f_name = "";     } }  // function user item , user id , find user status id , update function getstatus(id, curuser) {     var found = false;     (var = 0; < all_status.length; i++) {         if (all_status[i].the_user._id == id) {             curuser.status = all_status[i].status;             found = true;         }     }     if (!found) {         curuser.status = "";     } } function getphoto(id, curuser) {     var found = false;     (var = 0; < all_photo.length; i++) {         if (all_photo[i].the_user._id == id) {             curuser.photo = all_photo[i].photo;             found = true;         }     }     if (!found) {         curuser.photo = "";     } }  // return full user data updated wih status , first name response.success(json.stringify(all_users), "application/json"); 

it means undefined:

all_photo[i].the_user 

so undefined, doesn't have property _id, undefined objects have no properties, because undefined.

does define source of problem?

--

use browser console - helps:

console.log(all_photo); 

then can check out happening object , properties have after eval it.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -