Skip to content

MongoDB Protocol

prohaska edited this page Mar 21, 2013 · 5 revisions

This wiki captures the interaction between the mongo shell and mongod for various operations.

Create Database

  • Databases are created implicitly

Drop Database

  • Query <db>.$cmd dropDatabase
  • Query admin.$cmd replSetGetStatus

Create Collection

  • Query <db>.$cmd create <collection>, other attributes
  • Query admin.$cmd replSetGetStatus

Drop Collection

  • Query <db>.$cmd drop <collection>
  • Query admin.$cmd replSetGetStatus

Create Index

  • Insert <db>.system.indexes <collection>, index attributes
  • Query <db>.$cmd getlasterror
  • Query admin.$cmd replSetGetStatus

Drop Index

  • Query <db>.$cmd drop <collection>, <indexname>
  • Query admin.$cmd replSetGetStatus

Insert into a Collection

  • Insert <db>.<collection>, documents
  • Query <db>.$cmd getlasterror
  • Query admin.$cmd replSetGetStatus

Query a Collection

  • Query <db>.<collection>, query document, field selector document
    • Reply cursor, documents
  • Query admin.$cmd replSetGetStatus

Show collections

  • Query <db>.system.namespaces, query document, field selector document
    • Reply cursor, document
  • Query admin.$cmd replSetGetStatus

Count

  • Query <db>.$cmd, count <collection>, query document, field selector document
    • Reply cursor, document
  • Query admin.$cmd replSetGetStatus
  • If the <collection> does not exist, the reply returns 0.
Clone this wiki locally