Wernfried ← MongoDB Feedback Engine My feedback 21 results found Add support for db.exists() and collections.exists() 5 votes Vote Vote Vote We're glad you're herePlease sign in to leave feedback Signed in as (Sign out) Close Close Vote We’ll send you updates on this idea under review · 2 comments · MongoDB Shell » Commands · Delete… · Admin → How important is this to you? Not at all You must login first! Important You must login first! Critical You must login first! We're glad you're herePlease sign in to leave feedback Signed in as (Sign out) Close Close An error occurred while saving the comment Wernfried commented · May 23, 2022 · Edit… · Delete… 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') Save Submitting... ← Previous 1 2 Next →
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')