db.getCollection()

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: Database and collection discovery

What it does

Returns a collection object by name, including names awkward to access with dot notation.

Syntax

db.getCollection(name)

Use case

Access dynamically named collections.

db.getCollection(): practical example
db.getCollection("user-events").findOne()
💡 Explanation Returns a collection object by name, including names awkward to access with dot notation. When to use it Access dynamically named collections.
Key Takeaways
  • Returns a collection object by name, including names awkward to access with dot notation.
  • Typical use: Access dynamically named collections.