getCollectionInfos(filter?)
This method returns an array of documents with collection information, i.e. collection name and options, for the current database.
Syntax:
1. db.getCollectionInfos()
2. db.getCollectionInfos(collectionName)
Example 1: When the collection name is not specified
The following returns information for all collections in the example database:
use example
db.getCollectionInfos()
MongoDB
db.getCollectionInfos()
Output:
[{"name" : "example","type" : "collection","options" : {},"info" : {"readOnly" : false,"uuid" : UUID("9e942976-7f77-428c-995d-9ab1999fb61f")},"idIndex" : {"v" : 2,"key" : {"_id" : 1},"name" : "_id_"}},{"name" : "movies","type" : "collection","options" : {},"info" : {"readOnly" : false,"uuid" : UUID("2d9aee8b-ccad-4a0f-9a9a-5f953ec1c877")},"idIndex" : {"v" : 2,"key" : {"_id" : 1},"name" : "_id_"}}]
Example 2: When the collection name is specified
To request collection information for a specific collection, specify the collection name when calling the method.
use example
db.getCollectionInfos( { name: "movies" } )
MongoDB
db.getCollectionInfos( { name: "movies" } )
Output
[{"name" : "movies","type" : "collection","options" : {},"info" : {"readOnly" : false,"uuid" : UUID("2d9aee8b-ccad-4a0f-9a9a-5f953ec1c877")},"idIndex" : {"v" : 2,"key" : {"_id" : 1},"name" : "_id_"}}]
No comments:
Post a Comment