Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mongodb-preview.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

You can update a MongoDB view by replacing the view definition, or remove the view when it is no longer needed. To modify a view, you can either:
  • Drop and recreate the view.
  • Use the collMod command.

Example

Consider the following view named lowStock:
db.createView(
   "lowStock",
   "products",
   [ { $match: { quantity: { $lte: 20 } } } ]
)

Drop and Recreate the View

The following commands modify lowStock by dropping and recreating the view:
db.lowStock.drop()

db.createView(
   "lowStock",
   "products",
   [ { $match: { quantity: { $lte: 10 } } } ]
)

Use the collMod Command

Alternatively, you can use the collMod command to modify the view:
db.runCommand( {
   collMod: "lowStock",
   viewOn: "products",
   "pipeline": [ { $match: { quantity: { $lte: 10 } } } ]
} )