Skip to content

Instantly share code, notes, and snippets.

@pravynandas
Created November 21, 2023 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pravynandas/660645501e7a0be0f0655fb1ec10659a to your computer and use it in GitHub Desktop.
Save pravynandas/660645501e7a0be0f0655fb1ec10659a to your computer and use it in GitHub Desktop.
Push an item into an array type in mongo db through mongoose
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