MongoDB Show all contents from all collections

前端 未结 8 1769
刺人心
刺人心 2020-12-07 07:45

Is it possible to show all collections and its contents in MongoDB?

Is the only way to show one by one?

相关标签:
8条回答
  • 2020-12-07 08:04

    Step 1: See all your databases:

    show dbs
    

    Step 2: Select the database

    use your_database_name
    

    Step 3: Show the collections

    show collections
    

    This will list all the collections in your selected database.

    Step 4: See all the data

    db.collection_name.find() 
    

    or

    db.collection_name.find().pretty()
    
    0 讨论(0)
  • 2020-12-07 08:05

    This way:

    db.collection_name.find().toArray().then(...function...)
    
    0 讨论(0)
  • 2020-12-07 08:12

    Once you are in terminal/command line, access the database/collection you want to use as follows:

    show dbs
    use <db name>
    show collections
    

    choose your collection and type the following to see all contents of that collection:

    db.collectionName.find()
    

    More info here on the MongoDB Quick Reference Guide.

    0 讨论(0)
  • 2020-12-07 08:15
    var collections = db.getCollectionNames();
    for(var i = 0; i< collections.length; i++){    
       print('Collection: ' + collections[i]); // print the name of each collection
       db.getCollection(collections[i]).find().forEach(printjson); //and then print the json of each of its elements
    }
    

    I think this script might get what you want. It prints the name of each collection and then prints its elements in json.

    0 讨论(0)
  • 2020-12-07 08:21

    This will do:

    db.getCollectionNames().forEach(c => {
        db[c].find().forEach(d => {
            print(c); 
            printjson(d)
        })
    })
    
    0 讨论(0)
  • 2020-12-07 08:23

    step 1: Enter into the MongoDB shell.

    mongo

    step 2: for the display all the databases.

    show dbs;

    step 3: for a select database :

    use 'databases_name'

    step 4: for statistics of your database.

    db.stats()

    step 5: listing out all the collections(tables).

    show collections

    step 6:print the data from a particular collection.

    db.'collection_name'.find().pretty()

    0 讨论(0)
提交回复
热议问题