For AI agents: a documentation index is available at https://www.mongodb.com/ko-kr/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.

Modify or Remove a View

To remove a view, use the db.collection.drop() method on the view.

To modify a view, you can either:

  • Drop and recreate the view.

  • Use the collMod command.

Consider the following view named lowStock:

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

The following commands modify lowStock by dropping and recreating the view:

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

Alternatively, you can use the collMod command to modify the view:

db.runCommand( { collMod: "lowStock", viewOn: "products", "pipeline": [ { $match: { quantity: { $lte: 10 } } } ]} )