To remove a view, use the 要删除视图,请在视图上使用db.collection.drop() method on the view.db.collection.drop()方法。
To modify a view, you can either:要修改视图,您可以:
Example示例
Consider the following view named 考虑以下名为lowStock: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:lowStock:
db.lowStock.drop()
db.createView(
"lowStock",
"products",
[ { $match: { quantity: { $lte: 10 } } } ]
)
Use the collMod Command使用collMod命令
collMod CommandAlternatively, you can use the 或者,您可以使用collMod command to modify the view:collMod命令修改视图:
db.runCommand( {
collMod: "lowStock",
viewOn: "products",
"pipeline": [ { $match: { quantity: { $lte: 10 } } } ]
} )