English 中文(简体)
我怎么能够把在莫戈非行的所有藏品列入名单?
原标题:How can I list all collections in the MongoDB shell?

在MongoDB码头,我如何列出Im使用的现有数据库的所有收集资料?

最佳回答

......

Java:

db.getCollectionNames()

Node.js:

db.listCollections()

非贾瓦文(仅举):

show collections

我的理由是:

$ mongo prodmongo/app --eval "show collections"
MongoDB shell version: 3.2.10
connecting to: prodmongo/app
2016-10-26T19:34:34.886-0400 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell eval):1:5

$ mongo prodmongo/app --eval "db.getCollectionNames()"
MongoDB shell version: 3.2.10
connecting to: prodmongo/app
[
    "Profiles",
    "Unit_Info"
]

如果你真的想要这一轮,,那么你可以:

$ mongo prodmongo/app --eval "db.getCollectionNames().join( 
 )"
MongoDB shell version: 3.2.10
connecting to: prodmongo/app
Profiles
Unit_Info
问题回答
> show collections

如指挥线帮助所述,将列出目前选定的非行的所有收集资料(<条码>求助)。

我如何列出Im使用的现有数据库的所有收集资料?

Three methods

  • show collections
  • show tables
  • db.getCollectionNames()

To list all databases:

show dbs

To enter or use a given database:

use databasename

To list all collections:

show collections

产出:

collection1
collection2
system.indexes

(或)

show tables

产出:

collection1
collection2
system.indexes

(或)

db.getCollectionNames()

产出:

[ "collection1", "collection2", "system.indexes" ]

To enter or use given collection

use collectionname

<代码>>

其结果与卡梅伦的答复相同。

除其他人提出的选择外:

show collections  // Output every collection
show tables
db.getCollectionNames() // Shows all collections as a list

如果你想要知道如何建立每项收集资料,也可以真正地讲出另一种方式(例如,它是一种带有一定规模的限定收集):

db.system.namespaces.find()

首先,你们需要利用一个数据库来展示其内部的所有收集/表。

>show dbs
users 0.56787GB
test (empty)
>db.test.help() // this will give you all the function which can be used with this db
>use users
>show tables //will show all the collection in the db

Try:

help // To show all help methods
show dbs  // To show all dbs
use dbname  // To select your db
show collections // To show all collections in selected db

您可使用<条码> tables表或<条码>。

 1. show collections; // Display all collections
 2. show tables     // Display all collections
 3. db.getCollectionNames();   // Return array of collection. Example :[ "orders", "system.profile" ]

每次收集的详细信息:

db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )
  • For users with the required access (privileges that grant listCollections action on the database), the method lists the names of all collections for the database.
  • For users without the required access, the method lists only the collections for which the users has privileges. For example, if a user has find on a specific collection in a database, the method would return just that collection.

根据搜查令列出收集清单。

db.getCollectionNames().filter(function (CollectionName) { return /<Search String>/.test(CollectionName) })

<>>Example: 以“进口”名义进行的所有收集

db.getCollectionNames().filter(function (CollectionName) { return /import/.test(CollectionName) })

我认为,最大的混淆之一是你在<条码>mongo/code>(或互动/冲锋利)诉<条码>mongo-eval(或纯 Java本壳)方面所能做的区别。 我保存这些有益的文件:

这方面的一个例子是,你可能与<代码>show做些什么。 指挥:

# List all databases and the collections in them

mongo --eval "
    db.getMongo().getDBNames().forEach(
        function(v, i){
            print(
                v +  
	  +
                db.getSiblingDB(v).getCollectionNames().join( 
	 )
            )
        }
    )
"

说明:这项工作确实是一行。 (它看上去的是斯纳克多里。)

mongo --eval "db.getMongo().getDBNames().forEach(function(v, i){print(v+ 
	 +db.getSiblingDB(v).getCollectionNames().join( 
	 ))})"

邦戈舒尔的以下指挥是司空见惯的。

show databases
show collections

此外,

show dbs
use mydb
db.getCollectionNames()

有时,看到所有收集资料以及作为总名称空间一部分的收集索引是有益的:

在这方面,你将如何做到:

db.getCollectionNames().forEach(function(collection) {
    indexes = db[collection].getIndexes();
    print("Indexes for " + collection + ":");
    printjson(indexes);
});

在三军司令部和这支军之间,你应被很好地涵盖!

用于显示蒙戈巴数据库所有收藏品的指挥部是

show collections

在管理<代码>收集资料之前,必须选择数据库:

use mydb // mydb is the name of the database being selected

查阅所有数据库,你可以使用指挥系统。

show dbs // Shows all the database names present

详情见 查询>。

> show dbs        
anuradhfirst  0.000GB
local         0.000GB
> use anuradhfirst
switched to db anuradhfirst
> show collections
record
  • connect with the MongoDB database using mongo. This will start the connection.
  • then run show dbs command. This will show you all exiting/available databases.
  • then select the database you want. In the above it is anuradhfirst. Then run use anuradhfirst. This will switch to the database you want.
  • then run show collections command. This will show all the collections inside your selected database.

改用数据库。

:

<><>strong>use{your_database_name} 例如:

use friends

where friends is the name of your database.

然后写:

db.getCollectionNames()
show collections

这将使你获得收藏品的名称。

On;=2.x,你可以做

db.listCollections()

1. 你们可以做些什么

db.getCollectionNames()

www.un.org/Depts/DGACM/index_spanish.htm 登记在<代码>mongo上的所有收藏品:

  • db.getCollectionNames()
  • show collections
  • show tables

Note: Collections will show from current database where you are in currently

放映

这支指挥部通常在MongoDB飞机上工作,一旦你转至数据库。

任何人使用<> 甲型六氯环己烷

<编码>db.list_ Collection_names(>

For MongoDB 3.0 deployments using the WiredTiger storage engine, if you run db.getCollectionNames() from a version of the mongo shell before 3.0 or a version of the driver prior to 3.0 compatible version, db.getCollectionNames() will return no data, even if there are existing collections.

详情请见

利用<代码>mongo的以下指挥系统: 页: 1

show collections
show collections

show tables

db.getCollectionNames();




相关问题
Access DB Ref MongoDB

Whats the best way to access/query a DB Ref: UPDATE: users: name, groupref : {$ref:"groups",$id:"ObjectId ..." } } groups: name, topic, country,...,.. Assumption is that user belongs to only one ...

MongoDB nested sets

What re the best practices to store nested sets (like trees of comments) in MongoDB? I mean, every comment can have a parent comment and children-comments (answers). Storing them like this: { ...

MongoMapper and migrations

I m building a Rails application using MongoDB as the back-end and MongoMapper as the ORM tool. Suppose in version 1, I define the following model: class SomeModel include MongoMapper::Document ...

MongoDB takes long for indexing

I have the following setup: Mac Pro with 2 GB of RAM (yes, not that much) MongoDB 1.1.3 64-bit 8 million entries in a single collection index for one field (integer) wanted Calling .ensureIndex(...) ...

Storing and accessing large amounts of data

My application creates pieces of data that, in xml, would look like this: <resource url="someurl"> <term> <name>somename</name> <frequency>somenumber</...