These are chat archives for Automattic/mongoose

23rd
Jul 2018
Damien Marble
@ThisIsNoZaku
Jul 23 2018 18:40
Hello everyone. We encountered an issue in QA this morning with our node apps throwing "Topology was destroyed" errors after sitting idle for the weekend.
I assume it was some sort of idle timeout, but how can we ensure the connection doesn't close like that?
Brenda
@thehme
Jul 23 2018 18:43
@lineus thanks for checking this out, I will take a look at your comments
dan-gre
@dan-gre
Jul 23 2018 19:43
Hi all, is there a way I can use promise objects with mongoose queries?
mongoosebot
@mongoosebot
Jul 23 2018 20:09
:tada: We just released version 5.2.5 :tada:

5.2.5 / 2018-07-23

  • fix(boolean): expose convertToTrue and convertToFalse for custom boolean casting #6758
  • docs(schematypes): add note about what values are converted to booleans #6758
  • fix(document): fix(document): report castError when setting single nested doc to array #6753
  • docs: prefix mongoose.Schema call with new operator #6751 sajadtorkamani
  • docs(query): add examples and links to schema writeConcern option for writeConcern helpers #6748
  • docs(middleware): clarify that init middleware is sync #6747
  • perf(model): create error rather than modifying stack for source map perf #6735
  • fix(model): throw helpful error when passing object to aggregate() #6732
  • fix(model): pass Model instance as context to applyGetters when calling getters for virtual populate #6726 lineus
  • fix(documentarray): remove isNew and save listeners on CastError because otherwise they never get removed #6723
  • docs(model+query): clarify when to use countDocuments() vs estimatedDocumentCount() #6713
  • fix(populate): correctly set virtual nestedSchemaPath when calling populate() multiple times #6644
  • docs(connections): add note about the family option for IPv4 vs IPv6 and add port to example URIs #6566
Kev
@lineus
Jul 23 2018 20:37
@dan-gre Query objects are thenables which behave like promises. You can use them with async/await, Promise.all, or call their .then() and .catch() methods.
@thehme you're welcome. I hope it helps :smile:
@ThisIsNoZaku what connection settings are you passing into the connection?
Damien Marble
@ThisIsNoZaku
Jul 23 2018 20:41
@lineus Default ones.
dan-gre
@dan-gre
Jul 23 2018 21:02
@lineus Thanks! So I can use Model.create().catch + .then?
Kev
@lineus
Jul 23 2018 21:02
@ThisIsNoZaku assuming that the server wasn't interrupted while you were gone over the weekend and thereby causing the error, you might try increasing the value of of reconnectTries in your connection options to something like Number.MAX_VALUE and lowering your reconnectInterval to once a second.
@dan-gre yep :)
Damien Marble
@ThisIsNoZaku
Jul 23 2018 21:07
@lineus Thanks, we'll try that out.
dan-gre
@dan-gre
Jul 23 2018 21:08
Great, thanks @lineus
Kev
@lineus
Jul 23 2018 21:08
@ThisIsNoZaku sure! actually, I think the default reconnectInterval is 1000, so no need to change that :smile:
dan-gre
@dan-gre
Jul 23 2018 21:36
Hi everyone, I am querying using findOne(), matching to a specific field; however, it seems like the query is running as if it found a match, even when I input a value that is not present in the field. Anyone know why this is happening?
Damien Marble
@ThisIsNoZaku
Jul 23 2018 21:38
@dan-gre dip you mean it is finding something when it shouldn't?
dan-gre
@dan-gre
Jul 23 2018 22:36
It is sending back an empty object.
dan-gre
@dan-gre
Jul 23 2018 23:01
@ThisIsNoZaku I guess it is acting like it successfully found the requested ID and sends back an empty object, even though the ID that I sent through does not exist in any documents in the collection.
dan-gre
@dan-gre
Jul 23 2018 23:19
@ThisIsNoZaku I think I have fixed the issue - I was using findOne() with .then and .catch, but that query does not respond with an error if it does not find the id, instead it responds with null.
Does that seem correct? I now receive null when it cannot find the id, although I would prefer it responds with a not found error.
Damien Marble
@ThisIsNoZaku
Jul 23 2018 23:26
Yes, a query that finds nothing returns null.
If you check the docs for Mongoose queries, findOne returns a potentially-null single document.