getCollection( name )
Returns a collection or a view object that is functionally equivalent to using the
db.<collectionName>syntax. The method is useful for a collection or a view whose name might interact with the
mongoshell itself, such as names that begin with
_or that match a database shell method.
db.getCollection()method has the following parameter:
Parameter Type Description
string The name of the collection.
The following example uses
db.getCollection() to access the
auth collection and insert a document into it.
The previous example requires the use of
db.getCollection("auth") because of a name conflict with the database method
db.auth directly to perform an insert operation would reference the
db.auth() method and would error.
The following example attempts the same operation, but without using the
The operation errors as
db.auth() method has no