如何找出哪些管道已用于创建视图?
How do I find out which pipelines have been used for creating a view?
什么是 shell 命令来找出哪些管道已用于创建特定视图? MongoDB 版本为 3.6.4
此外,有没有办法使用 .net 驱动程序 2.6.1 版获取管道?
您可以使用 db.getCollectionInfos()
,并可选择指定 "filter" 条件作为查询。
例如:
// Insert Collection
db.test.insert({ "a": 1 })
// Create a view
db.createView("testView", "test", [{ "$match": { } }]);
// Get the information
db.getCollectionInfos({ "name": "testView" })
[
{
"name" : "testView",
"type" : "view",
"options" : {
"viewOn" : "test",
"pipeline" : [
{
"$match" : {
}
}
]
},
"info" : {
"readOnly" : true
}
}
]
请注意,"name"
匹配特定的集合,您甚至可以选择在 "type"
字段上筛选 "view"
以获取所有视图。管道清楚地显示在返回的输出中。
另请注意,此 "shell method" 只是包装了 listCollections
系统命令。大多数驱动程序在 "database" 对象上都有此方法的一些变体,或者它们可以以其他方式调用带有选项的命令。
什么是 shell 命令来找出哪些管道已用于创建特定视图? MongoDB 版本为 3.6.4
此外,有没有办法使用 .net 驱动程序 2.6.1 版获取管道?
您可以使用 db.getCollectionInfos()
,并可选择指定 "filter" 条件作为查询。
例如:
// Insert Collection
db.test.insert({ "a": 1 })
// Create a view
db.createView("testView", "test", [{ "$match": { } }]);
// Get the information
db.getCollectionInfos({ "name": "testView" })
[
{
"name" : "testView",
"type" : "view",
"options" : {
"viewOn" : "test",
"pipeline" : [
{
"$match" : {
}
}
]
},
"info" : {
"readOnly" : true
}
}
]
请注意,"name"
匹配特定的集合,您甚至可以选择在 "type"
字段上筛选 "view"
以获取所有视图。管道清楚地显示在返回的输出中。
另请注意,此 "shell method" 只是包装了 listCollections
系统命令。大多数驱动程序在 "database" 对象上都有此方法的一些变体,或者它们可以以其他方式调用带有选项的命令。