upog
upog

Reputation: 5531

find the database of a given collection

is there any command to find the databases which contains given collection in mongoDB

MongoDB Enterprise TestCluster-shard-0:PRIMARY> show dbs
admin               0.000GB
sample_airbnb       0.051GB
sample_analytics    0.009GB
sample_geospatial   0.001GB
sample_mflix        0.041GB
sample_supplies     0.001GB
sample_training     0.059GB
sample_weatherdata  0.002GB

Upvotes: 0

Views: 126

Answers (1)

prasad_
prasad_

Reputation: 14287

(1) Using mtools:

mtools is a collection of helper scripts to parse, filter, and visualize MongoDB log files.

mlogfilter is a mtools script to reduce the amount of information from MongoDB log files. You can specify a pattern or a word and search the log file. The collection name is usually specified as a "namespace" which is a combination of database and collection ("<database>.<collection>").

For example, look for the collection name:

mlogfilter mongod.log --word myCollection

This might return a lot of lines; you can just look at few lines and find your collection. There are a lot of options by which you can restrict the output (see the mtools documentation).


(2) From mongo Shell:

You can list all the databases (listDatabases) and all the collections (listCollections) from mongo shell. You can write a script to search each database for the specific collection.

Upvotes: 2

Related Questions