These are chat archives for Automattic/mongoose

11th
Jul 2018
atoscanoricardo
@atoscanoricardo
Jul 11 2018 11:59
Hi, I have an schema "Problem" with a array of ObjectId reference to other scheme "Rules"
image.png
I try to update propertie "productionRules" witch a Array of Id of "rules", I can't do this. de source is:
image.png
Ambika Kumar
@ambikarajbadal
Jul 11 2018 12:03
How to get dynamic data from variable in mongodb?
Kev
@lineus
Jul 11 2018 12:14
@ambikarajbadal can you elaborate on what you're hoping to do? Feel free to add some psuedo code if you think it will help make it more clear.
Ambika Kumar
@ambikarajbadal
Jul 11 2018 12:24
I'm expecting from mongodb like this mysql query "select * from campaignMaster where campaign_utm_source="'.$utm_source.'"' "
Where $utm_source is variable in PHP
@lineus
Kev
@lineus
Jul 11 2018 12:35
@ambikarajbadal here is an example
mongoosebot
@mongoosebot
Jul 11 2018 14:38
:tada: We just released version 5.2.3 :tada:

5.2.3 / 2018-07-11

  • fix(populate): if a getter is defined on the localField, use it when populating #6702 #6618 lineus
  • docs(schema): add example of nested aliases #6671
  • fix(query): add session() function to queries to avoid positional argument mistakes #6663
  • docs(transactions): use new session() helper to make positional args less confusing #6663
  • fix(query+model+schema): add support for writeConcern option and writeConcern helpers #6620
  • docs(guide): add writeConcern option and re-add description for safe option #6620
  • docs(schema): fix broken API links #6619
  • docs(connections): add information re: socketTimeoutMS and connectTimeoutMS #4789
panigrah
@panigrah
Jul 11 2018 15:45
@atoscanoricardo you need to put the async.each() inside the callback for the insertMany, otherwise they are not running sequentially.
panigrah
@panigrah
Jul 11 2018 15:52
Also why do you need to loop through problems? You could update multiple documents all in one go. Problem.update({_id: {$in: problems.map(p => p._id}, {$set.....}
Josh Gardner
@BeardedGardner_twitter
Jul 11 2018 20:24

Hey gang, I have a rather corner case mongoose question, for the ol' 4.13 version of mongoose. We're using the timestamps option in our schema, works great, everything is hunky dory. Unfortunately we're adding a function to our testing tool that will let our testers change the "createdAt" value for their users, and it seems like there's not an obvious way to do that?

The intuitive findOneAndUpdate(query, { createdAt: new Date() }) reports success but doesn't actually make any changes to the db. Is this the expected behavior?

Kev
@lineus
Jul 11 2018 22:07
@BeardedGardner_twitter did you figure out what was going wrong?
Kev
@lineus
Jul 11 2018 22:52
@BeardedGardner_twitter it looks like if you use the timestamps Schema option ( at least in 4.13 ), but want to override the createdAt date, you have to pass in overwrite: true to your query options. here's a quick example using mongoose 4.13.14
Kev
@lineus
Jul 11 2018 23:02
I don't think this specific use case is documented explicitly, but if you're curious as to why overwrite is necessary, there are several pre-hooks that get attached to the schema if you use the timestamps option, including one for findOneAndUpdate. Without the overwrite option set on the query options, mongoose will mutate your update doc to only allow $setOnInsert for createdAt. It's all in lib/schema.js in the Schema.prototype.setupTimestamp function.