These are chat archives for Automattic/mongoose

8th
Apr 2015
devmetrics.io
@devmetrics
Apr 08 2015 13:01
This message was deleted
devmetrics.io
@devmetrics
Apr 08 2015 13:06
This message was deleted
Andrew Andrew
@andrewandrew
Apr 08 2015 13:07
Hi, what's the best way to log all queries with their execution time (how much milliseconds did the query take)?
mongoose.set('debug', true) shows only the query, not the time.
It seems that pre/post query middleware could be used, but in this case I need to add this callbacks to every Scheme I have, it requires a lot of code changes.
I would like to change only one place in project, like it works with mongoose.set('debug', true). Any ideas?
Pavel Zubkou
@irnc
Apr 08 2015 13:33
@andrewandrew you can implement query middleware in plugin and use Mongoose#plugin to register it on all schemas, see http://mongoosejs.com/docs/api.html#index_Mongoose-plugin for reference
Andrew Andrew
@andrewandrew
Apr 08 2015 13:59
@irnc Thanks, plugin pipeline looks like a nice idea!
But is 'query' hook implemented in 3.8.*?
Tried MySchema.pre('query', myFunc) and MySchema.pre('findOne', myFunc), but neither seems to work in 3.8.*.
It works in 3.9.7, for example, which is not stable.
Stephen Ward
@guruward
Apr 08 2015 19:10
sorting by date with pagination, skip and limit seems to be the first operation then sort
in the mongoshell i get the sort first then can skip and limit which is what i want
Pavel Zubkou
@irnc
Apr 08 2015 23:44
@andrewandrew query middleware, such as find and findOne hooks was implemented in 4.0 branch, which is considered stable now, please check https://github.com/Automattic/mongoose/wiki/4.0-Release-Notes