Yep. I'm all about search engine titles this week.
In my new Mongo/mongoose world, I've exposed myself ot a ton of information, tutorials, explanations, examples, you name it and there is a HUGE thing that no one mentions.
Perhaps I'm an idiot or maybe the fact that I work entirely alone means that I am not privy to common knowledge so common that no one needs to say it but, I'm saying it now:
I had an object that, viewed with my general purpose display program, looks like this:
Doesn't look like it should be a problem. Addressing it as...
recipient gave me the first array element, an object.
recipient attempted to to address the object containing the email address and came back undefined.
Nothing I could do gave me the email address. It was insane.
Turns out that I could google the answer pretty easily once I realized what was going on but only after tearing my hair out because no one mentioned that mongoose produces bizarre data structures.
The answer is (drum roll, please)....lean()
as compared toquery.exec(wrapCallback(callback)); //this produces a mongoose object from hell
Obviously, if you are doing your processing in a model, you might really like the benefits of using the mongoose data type. I bet there are a TON of them but, if you are trying to construct a test, as I was, or send it to a web page, like I plan to do, you are going to want something that acts like a civilized citizen, not some rogue toxic waste factory.
Maybe you got to this note before you actually ruined yourself. Or, maybe you, like everyone else on earth, already know.