question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add overridden findOneAndDelete()

See original GitHub issue

When I need the document returned from a delete, I could do the following with remove():

const doc = await MySchema.remove({ _id: someId }).exec();
// Use doc

But with soft delete, the document is not returned, but instead a sort of status code:

const doc = await MySchema.delete({ _id: someId }).exec();
// doc = { n: 1, nModified: 1, ok: 1 }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dsanelcommented, Dec 9, 2018

@andreyrd in v0.5.0 we will have a method deleteById. I hope it will help you to easily use plugin. 😉

0reactions
farukboranncommented, Oct 26, 2022

how can i get deleted document in callback or something ? still work like that : { n: 1, nModified: 1, ok: 1 }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose overwrite the document rather that `$set` fields
It's "mongoose" that is doing this by adding $set into the "update object" where the standard driver would just pass that object through...
Read more >
Mongoose v6.8.2: API docs
An array containing all connections associated with this Mongoose instance. By default, there is 1 connection. Calling createConnection() adds a connection ...
Read more >
collection.findOneAndDelete() - MongoDB Stitch
Remove a single document from a collection based on a query filter and return a document with the same form as the document...
Read more >
db.collection.insert() — MongoDB Manual
Inserts a document or documents into a collection. The insert() method has the following syntax: db.collection.insert(.
Read more >
Collection - Node.js MongoDB Driver API
one will be added to each of the documents missing it by the driver, mutating the document. This behavior can be overridden by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found