Last Object in Array Goes Missing

45 views
Skip to first unread message

A

unread,
Jan 5, 2016, 4:16:49 PM1/5/16
to nodejs
Need suggestions, going crazy here

I am missing my last row of my object array called: data

console.log(data) //has 80 rows
Users.find({"_id": {$in: ids}}, {'_id':1, 'Fullname':1}, function(err, results) {  //i've used this query numerous times thought the whole site, nothing new
    console.log(data) //has 79 rows
      //... i do some stuff, but doesnt really matter ...//
});
                

Right after I run the mongoose  Users.find, the last element disappears; makes no sense to my why.  This happens every time, for every instance of the code run
I do have some code above it and after it, but I narrowed it down to these 3 lines.  Any Ideas? suggestions?  Row counts vary between execution 

A

unread,
Jan 6, 2016, 1:04:07 AM1/6/16
to nodejs
I take it back

i have a function after it that calls a splice of an index of -1, which seems like it gets rid of the last element
My other environments work because the index was >0 (search for specific index, where -1 was not found)

Back to sanity

A

unread,
Jan 6, 2016, 1:04:10 AM1/6/16
to nodejs
Some additional notes

Works fine in Test and Dev but not Prod, so the code is fine


On Tuesday, January 5, 2016 at 4:16:49 PM UTC-5, A wrote:

Ryan Graham

unread,
Jan 6, 2016, 1:04:18 AM1/6/16
to nodejs
Where is data defined? It is hard to tell from the limited context what else touches it.

Remember that your callback is being called after Users.find() returns, so if you are modifying that data array in any lines after that call to Users.find(), they will modify the data before your console.log() it the second time.

~Ryan

--
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 nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/616a18d2-3b06-4758-ace5-c2bb6780b3e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

~Ryan

J. Johnston

unread,
Jan 6, 2016, 11:34:49 AM1/6/16
to nodejs
If the rowcount changes each time you run the procedure it must be your data? 


On Tuesday, January 5, 2016 at 4:16:49 PM UTC-5, A wrote:

A

unread,
Jan 6, 2016, 11:34:49 AM1/6/16
to nodejs
I got it solved; looks like my 2nd reply came in late; the first one where I mention the splice was what solved the issue

I narrowed it down to those lines was incorrect because of async.  My console.log (really a diff custom function) writes to db vs console; so the delay on that made it seem at that moment the data was getting lost, but in actuality, that function finished and went on to another function before even the second log event ran 
Reply all
Reply to author
Forward
0 new messages