CosmosDB query multiple items

580 Views Asked by At

Hi i using Azure CosmosDB database,I trying to query multiple data in items .' In Collection is three array author_documents,book_documents,joining_documents. All data are filled up in these arrays. The Collection have this data:

[
    {
        "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": .....
    }
]

With this query works fine:

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

But with this query:

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

there is no records in database. I completely new with NoSQL databases. Why i cant query multiple items in collection?Is it possible to do that?

1

There are 1 best solutions below

4
Tiny Wang On

Containers can't communicate between others in cosmosdb, as op said he choose to use MongoDb instead.