2

嗨,我使用 Azure CosmosDB 数据库,我尝试查询项目中的多个数据。在 Collection 中是三个数组 author_documents、book_documents、joining_documents。所有数据都填充在这些数组中。收藏有以下数据:

[
    {
        "author_documents": [
            {
                "id": "a1",
                "name": "Thomas Andersen"
            },
            {
                "id": "a2",
                "name": "William Wakefield"
            }
        ],
        "book_documents": [
            {
                "id": "b1",
                "name": "Azure Cosmos DB 101"
            },
            {
                "id": "b2",
                "name": "Azure Cosmos DB for RDBMS Users"
            },
            {
                "id": "b3",
                "name": "Taking over the world one JSON doc at a time"
            },
            {
                "id": "b4",
                "name": "Learn about Azure Cosmos DB"
            },
            {
                "id": "b5",
                "name": "Deep Dive into Azure Cosmos DB"
            }
        ],
        "joining_documents": [
            {
                "authorId": "a1",
                "bookId": "b1"
            },
            {
                "authorId": "a2",
                "bookId": "b1"
            },
            {
                "authorId": "a1",
                "bookId": "b2"
            },
            {
                "authorId": "a1",
                "bookId": "b3"
            }
        ],
        "id": "33a127b7-a0b6-4207-8092-caf15aaae820",
        "_rid": "......",
        "_self": ".......",
        "_etag": "........",
        "_attachments": ".....",
        "_ts": .....
    },
    {
        "author_documents": [
            {
                "id": "a3",
                "name": "Thomas Andersen"
            }
        ],
        "id": "271ffe0c-56c1-4eec-be6c-a5b1d6ff6e72",
        "_rid": ".......",
        "_self": ".....",
        "_etag": "....",
        "_attachments": "......",
        "_ts": .....
    },
    {
        "book_documents": [
            {
                "id": "b7",
                "name": "Azure Cosmos DB 101"
            }
        ],
        "id": "c88a968e-4d4e-4a25-be6b-4661f314b7c5",
        "_rid": "....",
        "_self": "...",
        "_etag": ".....",
        "_attachments": ".....",
        "_ts": 1619172859
    },
    {
        "joining_documents": [
            {
                "authorId": "a3",
                "bookId": "b7"
            }
        ],
        "id": "9c7279ab-9e13-4a39-b61b-a03ad2b2652a",
        "_rid": "==",
        "_self": "/....",
        "_etag": ".......",
        "_attachments": "......",
        "_ts": .....
    }
]

使用此查询可以正常工作:

SELECT t.authorId,t.bookId,f.name FROM  a 
join f in a.author_documents 
JOIN t IN a.joining_documents  where t.bookId="b2" and f.id = t.authorId

但是有了这个查询:

SELECT t.authorId,t.bookId,v.name FROM  a 
JOIN t IN a.joining_documents
join v in a.author_documents  where t.bookId="b7" and v.id = t.authorId

数据库中没有记录。我对 NoSQL 数据库完全陌生。为什么我不能查询集合中的多个项目?可以这样做吗?

4

1 回答 1

1

容器无法在 cosmosdb 中的其他容器之间进行通信,正如 op 所说,他选择使用 MongoDb 代替。

于 2021-04-23T14:56:14.840 回答