These are chat archives for Automattic/mongoose

6th
Feb 2017
Paul "Joey" Clark
@joeytwiddle
Feb 06 2017 09:19
@Strutsagget Googling got me https://www.npmjs.com/package/mongoose-ui-forms and http://stackoverflow.com/questions/11409819/admin-panel-for-node-js-and-mongoose but I cannot recommend any as I have not tried them.
nacq
@nacq
Feb 06 2017 14:08
Hello guys, being ‘./User’ my mongoose model definition, anyone knows with this post hooks are not being fired?
const Model = require('./User’)
const EventEmitter = require('events’)
const EE = new EventEmitter()

EE.setMaxListeners(0)

Model.schema.post('save', function (doc) {
  EE.emit(`save:${doc._id}`, doc)
  EE.emit('save', doc)
})

Model.schema.post('remove', function (doc) {
  EE.emit(`remove:${doc._id}`, doc)
  EE.emit('remove', doc)
})
Stephan Kristyn
@nottinhill
Feb 06 2017 15:02
Hi... @nacq so post hooks are possible by default?
nacq
@nacq
Feb 06 2017 15:04
@nottinhill hi man! What u mean ?
Stephan Kristyn
@nottinhill
Feb 06 2017 15:17
Why do you emit?
nacq
@nacq
Feb 06 2017 15:24
I emit those event for later emit to the UI via socket io
The thing is that the hooks are not being fired, but if I define that hooks on the same file where the Model definition is, it works
Stephan Kristyn
@nottinhill
Feb 06 2017 15:31
Could you send me the file of your working model definition on gist?
nacq
@nacq
Feb 06 2017 15:31
Sure, gimme a sec
Stephan Kristyn
@nottinhill
Feb 06 2017 15:31
I did not know that this is possible so easy.
Cool
Stephan Kristyn
@nottinhill
Feb 06 2017 15:36
nice!
.post hook also possible?
Also more importantly... with a posthook, does Mongoose give us back the data from DB?
nacq
@nacq
Feb 06 2017 15:43
Yea it gives you the document as the first parameter in the callback
Stephan Kristyn
@nottinhill
Feb 06 2017 15:48
Nice
Found it
Thanks a lot