MongoDB.live, free & fully virtual. June 9th - 10th. Register Now MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

MongoDB / Discord.js - checking existence of a collection

Hello everyone !

I make a discord bot with mongoDB and I create a command to modify an article from my bot’s shop.
Before modifying a particular article, it must already be found in the database. Is it possible to find out if the name typed in the command exists in the database ? If it does not exist, it returns an error message.

Thank you and good evening !

you can use this query to check if NONE returns …

db.collection.find({_id: "some_id"}, {_id: 1}).limit(1)

based on the response, you can use a javascript to check to display the approirate message.