如何找出用于创建视图的管道?

时间:2018-05-28 08:26:39

标签: mongodb view mongodb-.net-driver

用于查找哪些管道用于创建特定视图的shell命令是什么? MongoDB版本是3.6.4

此外,有没有办法使用.net驱动程序,版本2.6.1?

获取管道

1 个答案:

答案 0 :(得分:2)

您可以使用db.getCollectionInfos(),并可选择指定"过滤器"条件作为查询。

例如:

// 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"与特定集合相匹配,您甚至可以选择在"view"字段上过滤"type"以获取所有观看次数。管道清楚地显示在返回的输出中。

另请注意这个" shell方法"只需包装listCollections系统命令。大多数驱动程序在"数据库"上有一些这种方法的变体。对象或者他们只能通过选项调用命令。