Docs Menu
Docs Home
/
MongoDB Manual
/

DDL Operations

On this page

  • Explicit DDL Operations
  • Implicit DDL Operations

DDL (Data Description Language) operations change the properties of a database or collection. MongoDB supports both Explicit DDL Operations and Implicit DDL Operations. Explicit DDL operations directly run an operation like creating or dropping a collection or index. Implicit DDL operations create collections by referencing a non-existent collection, like inserting data into a non-existent collection.

MongoDB supports the following explicit DDL operations:

MongoDB also supports write operations such as insert or update with upsert:true. Any command that writes to a non-existing collection creates that collection.

For example, this insert command creates the users collection if it does not already exist.

db.runCommand(
{
insert: "users",
documents: [ { _id: 1, user: "abc123", status: "A" } ]
}
)

This update command with upsert: true creates the people collection if it does not already exist.

db.runCommand(
{
update: "people",
updates: [
{ q: { name: "Andy" }, u: { $inc: { score: 1 } }, upsert: true }
]
}
)

Back

updateSearchIndex