Is it possible to use MongoDB Views with Azure CosmosDB?

[亡魂溺海] 提交于 2019-12-24 19:53:13

问题


I tried to create a view via Robo3T. The command executes successfully, but the view is always empty, no matter how I specify the aggregation pipeline for the view. Example:

db.createView("testView","originCollection", [{
    $project : {
        _id: 1
    } 
}])

Does CosmosDB even support views for MongoDB?


Edit: As Kevin Smith asked in comments db.testView.stats() returns:

{
    "_t" : "CollStatsResponse",
    "ok" : 1,
    "ns" : "myDb.testView",
    "count" : 0.0,
    "size" : 0,
    "avgObjSize" : 0,
    "numExtents" : 0,
    "lastExtentSize" : 0,
    "paddingFactor" : 0,
    "systemFlags" : 0,
    "userFlags" : 0,
    "totalIndexSize" : 0,
    "indexSizes" : {
        "indexSizes" : {}
    }
}

回答1:


From the details that you have given, it looks like it's treating the view as just another collection and nothing is happening when you create a view (I've seen this with other commands it just continues without any errors).

When you call stats on a view you'd normally end up with the following

db.testView.stats()
{
    "ok" : 0,
    "errmsg" : "Namespace test.testView is a view, not a collection",
    "code" : 166,
    "codeName" : "CommandNotSupportedOnView"
}

Also, looking at the documentation (https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-feature-support#administration-commands) the Administration Commands don't support createView.



来源:https://stackoverflow.com/questions/55060005/is-it-possible-to-use-mongodb-views-with-azure-cosmosdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!