Function queryDoc

  • Query document with a query language

    The usage of query language for example we have a document looks like the following

        {
    "firstName": "John",
    "lastName": "Doe",
    "age": 28,
    "pets": [
    {"name": "Rexy rex", "kind": "dog", "likes": ["bones", "jumping", "toys"]},
    {"name": "Grenny", "kind": "parrot", "likes": ["green color", "night", "toys"]}
    ]
    }
    1. Query one document from collection
    const queryStr = '/* | limit 1'
    const resultSet = await queryDoc<Profile>(collection, queryStr)
    1. Query documents with filter
    const queryByName = '/[firstname="John"]'
    const resultSet = await queryDoc<Profile>(collection, queryByName)
    const queryByFirstAndLast = '/[firstName="John"] and [lastName="Doe"]'
    const resultSet = await queryDoc<Profile>(collection, queryByName)
    1. Query documents with filter and projection
    // only query the firstName and lastName
    const queryByName = '/[firstname="John"] | / {firstName, lastName}'
    const resultSet = await queryDoc<Profile>(collection, queryByName)
    1. Query documents with filter and aggregate count
    // only query the firstName and lastName
    const queryByNameAndCount = '/[firstname="John"] | count'
    const resultSet = await queryDoc<Profile>(collection, queryByNameAndCount)

    Type Parameters

    Parameters

    • col: Collection

      the instance of collection

    • queryStr: string

      a document query string

    • Optional parameters: QueryParameter[]

      an optional query parameters

    Returns Promise<QueryResult<unknown>>

    the QueryResult

Generated using TypeDoc