Function find

  • Find an item using one of its collection's access patterns

    This method is very strict about how the query object is used. Failure to specify it

    Each of its keys is one of the keys paths to a field in the collection objects (separated by a full-stop .), with the values set to the value to match against. The value is a direct string comparison, so only string values can be looked up (the query object cannot contain nested values or values of types other than string)

    Every path that is specified must be part of the same access pattern. You cannot have extraneous fields to match or mix keys from different access patterns.

    All of the key paths in the partition key part of the access pattern must be specified.

    You do not have to specify all of the sort keys, but because they are stored as a composite key, and we can only do begins_with match, you must specify the keys in the order they appear, only leaving off those at the end.

    For example, if your sort key is defined as:

    [['state'], ['city'], ['street', 'name'], ['street', 'number']]

    you could specify any of the following combinations:

    • { state: '...' }
    • { state: '...', city: '...' }
    • { state: '...', city: '...', 'street.name': '...' }
    • { state: '...', city: '...', 'street.name': '...', 'street.number': '...' }

    But these would be invalid:

    • { city: '...' }
    • { state: '...', 'street.name': '...' }
    • { city: '...', 'street.name': '...', 'street.number': '...' }

    Type Parameters

    Parameters

    • ctx: Context

      the context object

    • collectionName: string

      the collection name

    • query: FindQuery

      an object, with each of its keys set to the path of each field in the search object to match and their corresponding values to match (see above)s

    • Optional nextToken: Key

      pagination token

    • options: FindOptions = {}

      options controlling the query

    Returns Promise<FindResults<DocumentType>>

    an object containing the items found and a pagination token (if there is more results)

    Throws

    [[CollectionNotFoundException]] when the collection is not found in the context

    Throws

    [[InvalidQueryException]] when the access pattern cannot be found for the specfied combination of query key paths

Generated using TypeDoc