These are chat archives for Automattic/mongoose

20th
Dec 2017
pixiuPL
@pixiuPL
Dec 20 2017 12:44
ok
Jenky W. Nolasco
@jenkynolasco11
Dec 20 2017 12:54

Good morning, everybody, I have a question:

I have an application that, when it starts, it creates a bunch of documents and saves them, then I have a service that queries those documents, pass the info to another app, gets the info modified and depending of the results, updates such documents, and the process repeats until finished. Everything works perfectly fine, up to the point where, after certain amount, mongoose stops working in the same way, it just doesn't update them at all. I have put a lot of console.logs all over the application to check that the functions with mongoose are going to be executed, and indeed they are going to, but this really had me googling on the internet for an answer...

Have you guys experienced this kind of behaviour before?

Juha Lindstedt
@pakastin
Dec 20 2017 13:16
Have you tried to set mongoose debug on?
Jenky W. Nolasco
@jenkynolasco11
Dec 20 2017 13:24
I am going to check that, so I specifically see what's going on. I'll be back and report results
Juha Lindstedt
@pakastin
Dec 20 2017 13:25
👍
Jannis "Nexor" Betz
@neXorianus
Dec 20 2017 17:11

Hi there,
any chance to update another property on update/save?

Schema.post('findOneAndUpdate', (doc) => {
  if (doc.count !== doc.things.length) {
    this.model.update({ _id: doc._id }, { $set: { count: doc.things.length } });
  }
});

something like that?
courrently this gives me errors (Cannot read property 'update' of undefined) and I guess, i could run into an update-loop?

Andrew Lavers
@alavers
Dec 20 2017 17:16

I have a question about autoReconnect (true) and bufferMaxEntries (-1). I've got an app using mongoose, pointing at a ReplSet, and have successfully tested the query queuing behavior during a primary failover (as described in this article http://mongodb.github.io/node-mongodb-native/2.0/tutorials/connection_failures/)

However, in production I occasionally see brief remote connection closures, producing a Error: read ECONNRESET at exports._errnoException MongoError. The connection is restored in seconds, however the affected queries do not get queued, and instead the web request fails.

Is query buffering supposed to work in these cases?

Am particularly curious about the comment at the end of the article from Elad Nava: "Scheduled replica set step-downs would cause outstanding queries to fail with "Could not locate any valid servers in initial seed list", "sockets closed", and "ECONNRESET" before additional queries would get buffered up even though bufferMaxEntries is correctly configured."
Andrew Lavers
@alavers
Dec 20 2017 17:40
OK, in the end, I think I'm confusing two things: 1) buffering incoming queries during an outage and 2) failing queries that happen to be in flight the moment the connection is lost
🦆
I guess the follow-up question is what options could mongoose offer for catching and retrying failed queries?