mongoose-trigger | Mongoose plugin to automatically emit needed events | Pub Sub library
kandi X-RAY | mongoose-trigger Summary
kandi X-RAY | mongoose-trigger Summary
Mongoose plugin to automatically emit needed events. This modules lets you attach event listeners directly to your models and emit event at any mongoose hook you want in an extremly flexible way.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of mongoose-trigger
mongoose-trigger Key Features
mongoose-trigger Examples and Code Snippets
Community Discussions
Trending Discussions on mongoose-trigger
QUESTION
I have a nodeJS server which maintains a MongoDB and a client which sends a post request with a buildName variable in JSON.
What I am trying to do is setup an event listener that is triggered when the mongoDB document with a field matching the buildName sent by the client is updated or created. Multiple clients can be listening and must be notified if a document containing the same buildName that they pass in is updated or created.
I have tried to do polling with this method where my client just sat in a while loop and constantly asked if there was an update, however, I ran into performance issues so I switched to event listeners.
I tried a few different ways of setting up a callback when my client sends its post request which gets called whenever a document is updated and then sends that updated mongodb doc as a res.json
. One of the ones I am using is mongoose-trigger npm module which allows me to setup event listeners for both creates and updates.
I also looked on here for possible solutions which brought me to mongoose-trigger for getting events triggered on creates and updates, but still could not find an answer that satisfied using this triggering to fire off a response to a post request.
Here is a snippet of the code for creating the triggering event object:
...ANSWER
Answered 2018-Apr-10 at 15:16You need to remove the callback pairs you attached as soon as one of them has been called. To be able to do so, you cannot you anyonmous function, but have to use named functions instead:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install mongoose-trigger
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page