Logging outbound queries

3,100 views
Skip to first unread message

Scoopster

unread,
Feb 11, 2012, 2:51:57 AM2/11/12
to Mongoose Node.JS ORM
Is there a way to log all the queries fired by Mongoose towards
mongodb? I can see how it'll be very useful as a debugging tool.

I'm also running into this issue and any pointers to help me debug
would be very helpful:

var comments = new Schema ({
userId : { type: Schema.ObjectId, ref: 'User' }
, postId : { type: Schema.ObjectId, ref: 'post' }
, text : String
});

And I'm trying something like:

var objId = new mongoose.Types.ObjectId("4efd45859b9ca8a01c000016");
commentsModel.find( {userId: objId} } , function (err, doc){

This kind of lookup is not working for any field that is and ObjectId.
The same works from the mongo console.

I've tried all I can but fail to understand why the query doesn't
select any results. If can Iog the query that goes to Mongo, then I
may be able to see whether it's a user error or mongoose issue or
something else.

Any help would be awesome.

Thanks

Aaron Heckmann

unread,
Feb 11, 2012, 7:41:45 AM2/11/12
to mongoo...@googlegroups.com
On Sat, Feb 11, 2012 at 2:51 AM, Scoopster <scoop...@gmail.com> wrote:
Is there a way to log all the queries fired by Mongoose towards
mongodb? I can see how it'll be very useful as a debugging tool.

mongoose.set('debug', true)

or

mongoose.set('debug', function (collectionName, method, query, doc [, options]) {
 //
})

--
Aaron


David Galindo

unread,
Dec 28, 2013, 2:32:09 PM12/28/13
to mongoo...@googlegroups.com
Aaron, you're crazy man, you've been very helpful. Thanks!

Aaron Heckmann

unread,
Jan 4, 2014, 6:42:43 PM1/4/14
to mongoo...@googlegroups.com
:D
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


--

Billy Newman

unread,
May 20, 2014, 10:40:55 PM5/20/14
to mongoo...@googlegroups.com
how does mongoose format the log? IE I would like to use the second option to let winston log. I like the format mongoose logs and I would format my log w/ winston the same way.  Searching through code but have not been successful finding the format used to log to the console.  Can you point me to the right file/line number?
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Jason Crawford

unread,
May 20, 2014, 10:52:06 PM5/20/14
to mongoo...@googlegroups.com
I was able to get Mongoose logging through Winston by starting it like this:

var logger = new winston.Logger({…});
mongoose.connect(uri, {server: {logger: logger}}, function () { … })

Hope that helps,
Jason

--
Blog: http://blog.jasoncrawford.org  |  Twitter: @jasoncrawford




To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kenny DiFiore

unread,
Sep 20, 2016, 9:41:33 AM9/20/16
to Mongoose Node.JS ODM
Aaron,

When setting mongoose.set('debug', true), I can't take the output and copy it into mongo shell.  How should the output be formatted so that I can just copy it into mongo shell to repeat the query?

-Kenny
Reply all
Reply to author
Forward
0 new messages