Find and findOne returns properties in doc._doc but not doc

548 views
Skip to first unread message

murvinlai

unread,
Sep 12, 2011, 1:52:00 PM9/12/11
to Mongoose Node.JS ORM
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.



Tom Blobaum

unread,
Sep 12, 2011, 7:29:45 PM9/12/11
to mongoo...@googlegroups.com
What version of mongoose? You'll want to provide enough code to recreate the problem.

--
http://mongoosejs.com
http://github.com/learnboost/mongoose
You received this message because you are subscribed to the Google
Groups "Mongoose Node.JS ORM" group.
To post to this group, send email to mongoo...@googlegroups.com
To unsubscribe from this group, send email to
mongoose-orm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en

murvinlai

unread,
Sep 13, 2011, 1:06:43 PM9/13/11
to Mongoose Node.JS ORM
The lastest Mongoose 2.0. I would like to provide more code, but it
is like 10 modules, which is my entire program. :)

I believe it has something to do with module conflict. I will include
the list of modules.

On Sep 12, 4:29 pm, Tom Blobaum <tblob...@gmail.com> wrote:
> What version of mongoose? You'll want to provide enough code to recreate the
> problem.
>
> Thomas Blobaumhttp://twitter.com/tomblobaum
Reply all
Reply to author
Forward
0 new messages