Created
November 21, 2023 02:00
-
-
Save pravynandas/660645501e7a0be0f0655fb1ec10659a to your computer and use it in GitHub Desktop.
Push an item into an array type in mongo db through mongoose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let options = { "upsert": true, "new": true }; | |
let update = { "$push": { } }; | |
update["$push"]["receipts"] = url; | |
Tran.findByIdAndUpdate(id, update, options, function(err, tran) { | |
if (err) { | |
res.status(500).json({ error: err.message }) | |
} else { | |
res.status(200).json({ message: 'Item pushed successfully.' }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment