These are chat archives for Automattic/mongoose

21st
Mar 2019
Peter Kuijpers
@ReaperOfVeriod
Mar 21 00:48

hey guys been using mongoose for an api i build i get a deprication warning in my console "(node:14052) DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead."

however i am using ''findOneAndUpdate'' already?

exports.updateUser = function(req, res) {
User.findOneAndUpdate({_id: req.params.UserId}, {$set: req.body}, {new: true}, function(err, user) {
if (err)
res.send(err);
res.json(user);
});
};

any ideas what might be wrong?

pusaphil
@pusaphil
Mar 21 06:47

i am new to NodeJS and working with the ff packages:
mongoose v5.0.9
seneca v3.4.3 with seneca-amqp-transport and rabbitMQ as a broker (not sure if terminology is correct)

i noticed that if i have a simple seneca listener script (RPC) with rabbitMQ connection alone, no mongoose connection, the listener script dies after the rabbitMQ dies. This is because somehow seneca emits a 'kill' signal which okay with me. I want the listener script to die if it got disconnected to rabbitMQ.
But if the seneca listener script (RPC) have rabbitMQ and mongoose connections, and the rabbitMQ dies, the listener script is still up and running. Somehow the mongoose is keeping the connection or the script up and running.

See output below:

INFO [2019-03-21T06:37:23.934Z] (27933 on mylaptop): Workers initialized...
^CINFO [2019-03-21T06:37:33.382Z] (27933 on mylaptop): -- Executing SIGINT listener...
INFO [2019-03-21T06:37:33.384Z] (27933 on mylaptop): Closing Database connection.
INFO [2019-03-21T06:37:33.387Z] (27933 on mylaptop): Closing Message broker.
INFO [2019-03-21T06:37:33.388Z] (27933 on mylaptop): Message broker closed.
INFO [2019-03-21T06:37:33.389Z] (27933 on mylaptop): Database connection closed.
INFO [2019-03-21T06:37:33.391Z] (27933 on mylaptop): Graceful exit done. Terminating process...
INFO [2019-03-21T06:37:33.391Z] (27933 on mylaptop): -- Executing exit listener...
INFO [2019-03-21T06:37:33.391Z] (27933 on mylaptop): Closing Database connection.
INFO [2019-03-21T06:37:33.392Z] (27933 on mylaptop): Database connection closed.
INFO [2019-03-21T06:37:33.392Z] (27933 on mylaptop): Closing Message broker.
INFO [2019-03-21T06:37:33.392Z] (27933 on mylaptop): Message broker closed.

As you can see, i triggered the Ctrl+C (SIGINT) because the listener script did respond to the rabbitMQ shutdown, but you can also see that the -- Executing exit listener... - the exit signal by seneca - is already in the event loop of NodeJS but somehow not prioritized(?)/executed by NodeJS.

I want to know why? Is there a way to bypass this and prioritize the 'kill' signal.

pusaphil
@pusaphil
Mar 21 09:05
Correction: i triggered the Ctrl+C (SIGINT) because the listener script did not respond to the rabbitMQ shutdown,
Daniel Lee
@DanielL38119712_twitter
Mar 21 21:22
Anybody help me?