How to find duplicate documents in a MongoDB collection?

In this post we will show you how to find duplicate documents in your existing database using MongoDB’s aggregation pipeline. Let’s take a sample employees collection for this post. I’ve inserted the following documents into the employees collection. > db.employees.insertOne({employeeId: 1, employeeName: “Anand”}) { “acknowledged” : true, “insertedId” : ObjectId(“5f2cfbcf0694cb7ba344f46b”) } > db.employees.insertOne({employeeId: 2, employeeName: “Wayne”}) { “acknowledged” : … Read more

Update if exists, insert if it doesn’t exist – How to do Upsert in Mongoose?

To find a document and update it using Mongoose, you can use the findOneAndUpdate schema method. As the name implies, findOneAndUpdate() filter the document first that matches a given filter, applies an update, and returns the document.  Roles.findOneAndUpdate({role:req.params.role},{modules: req.body.modules}); But what if the document that is to be updated doesn’t exist? You can insert it as a new document, … Read more

How to kill a zombie process in Linux?

On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution (via the exit system call) but still has an entry in the process table: it is a process in the ‘Terminated state’. In short, a process which has finished the execution but still has entry in the process table to report to its parent process … Read more