Here is what my script look like:
UserModel.findOne(
{userId:'xx123456'},
function(err, doc) {
if (err) {
next(err);
} else if (! doc) {
next( 'findOne: User not found. Input: ' +
JSON.stringify(data)));
} else {
next(null, {status:true,
message:'User is found' ,
data:doc
});
}
}
);
When I run unit test in command line, doc has the properties. e.g.
{userId:'xx123456', name:"My Name' }
However, when I make a web app calling this function passing exactly
the same userId, doc.userId is empty. However, I can find the data in
doc._doc. why is that? doc contains doc._prototype
doc._<functions>, doc.isNew and doc._doc for the properties. I need
to access my properties like that: doc._doc.userId doc._
doc.name.
I have to do this JSON.parse(JSON.stringify(doc)) in order to make the
properties right under doc. i.e. doc.userId,
doc.name.
I have another site that return the full document from "doc"
normally.
I have a feeling that something wrong with the Model.init function.