Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Under Consideration
Categories MongoDB Shell
Created by Guest
Created on Feb 11, 2021

Add support for db.exists() and collections.exists()

Add a db.exists() and collections.exists() so that it is easy to check whether a database or a collection exists. This will help to reduce the propensity to inadvertently create new dbs and collections when running a script due to typos.
  • Guest
    May 23, 2022
    Can be done with a single command: db.exists() -> db.adminCommand( { listDatabases: 1 , filter: { name: 'db' } } ).databases.length > 0 and collections.exists() -> db.getCollectionNames().includes('collections')
  • Guest
    Feb 11, 2021
    This is the re-created version of https://jira.mongodb.org/browse/SERVER-1938?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&focusedCommentId=3611783#comment-3611783 where a lot of discussion has already taken placE.