-1

I am making an insert with native mongodb for nodejs and in some cases, using insert returns me an array with the object I inserted, but sometimes it does not. I don't understand why it is inconsistent like this, I only want the object i inserted (which now includes _id) without the array wrapper, or, always return it WITH that wrapper.

Why does it do this?

Discipol
  • 3,137
  • 4
  • 22
  • 41

1 Answers1

2

The only time the second parameter to your callback won't be an array of the inserted documents is when the first parameter is non-null to indicate an error occurred. See docs.

JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
  • I can confirm I handled the error properly and it didn't pop. I wouldn't have gotten the value at all in my client :| I shall test out what happens to the error in those 2 cases. I will reply what happened. – Discipol Jun 08 '13 at 18:25
  • 1
    turns out im a dumb little monkey. a findOne function was returning the non array :D very hilarious – Discipol Jun 08 '13 at 18:54