These are chat archives for Automattic/mongoose

12th
Nov 2018
Slim Hmidi
@slim-hmidi
Nov 12 2018 15:10
Hi, I update a document using mongo shell using updateOne() and when I tried to get the modification using findById. I got the old document, not the updated one. Is there any option to be added in order to return the new document after updating it?
paulogdm
@paulogdm
Nov 12 2018 16:12

Hello people, I'm reaching out to you today to ask for some help.
I'm trying to deploy an app on now v2 (AWS lambda) but I'm getting an error:

Error while initializing entrypoint: { Error: ENOENT: no such file or directory, open '/var/task/user/code-points.mem'
                              at Object.fs.openSync (fs.js:646:18)
                              at Object.fs.readFileSync (fs.js:551:33)
                              at Object.<anonymous> (/var/task/user/src/mongo.js:1:315280)
                              at Module._compile (module.js:652:30)
                              at Object.Module._extensions..js (module.js:663:10)
                              at Module.load (module.js:565:32)
                              at tryModuleLoad (module.js:505:12)
                              at Function.Module._load (module.js:497:3)
                              at Module.require (module.js:596:17)
                              at require (internal/module.js:11:18)
                            errno: -2,
                            code: 'ENOENT',
                            syscall: 'open',
                            path: '/var/task/user/code-points.mem' }

The code is located here: https://github.com/paulogdm/micro-example-now-v2
But you can see a live version here: https://nodejs-a5snryqj6.now.sh/_logs

Any help is very much appreciated.

Berian
@chaiwa-berian
Nov 12 2018 17:34
@slim-hmidi If you want the updateOne method to return the updated document, yes you need to pass the {new: true} option as below:
YourModel.updateOne({_id: 'whatever_id'}, your_update_query_doc, {new: true}, function(error, updated_doc){
     console.log(updated_doc);
     //do other things here with the newly updated doc
});
Charlie
@charliecode
Nov 12 2018 19:21
Hey guys, does anyone have experience with querying an array of subdocuments based on criteria and only returning said docs?
Charlie
@charliecode
Nov 12 2018 20:20
Hello?
Anybody home?
lol