returnnewdocument

Solutions on MaxInterview for returnnewdocument by the best coders in the world

showing results for - "returnnewdocument"
Shadrach
30 Apr 2018
1// /node-mongodb-native//4.0 driver 
2//returnOriginal is Deprecated Use options.returnDocument instead.
3returnDocument	'before' | 'after'
4When set to 'after',returns the updated document rather than the original
5When set to 'before',returns the original document rather than the updated.
6The default is 'before'.
7
8const options = { returnDocument: 'after' };
9//same for findOneAndReplace
10myDataBase.findOneAndUpdate(query, update, options, (err, doc) => {
11   if (err) {
12          console.log("Something wrong when updating data!");
13        }
14        else if (!doc.lastErrorObject.updatedExisting && doc.value == null)
15          return res.json('no book exists')
16  
17 // The updated document is held within the value property of the response
18        console.log('doc.value');
19        console.log(doc.value);
20})
21
22//https://stackoverflow.com/a/67909382/918069/
23