Containers class
Operations for creating new containers, and reading/querying all containers
See Container for reading, replacing, or deleting an existing container; use .container(id)
.
Note: all these operations make calls against a fixed budget.
You should design your system such that these calls scale sublinearly with your application.
For instance, do not call containers.readAll()
before every single item.read()
call, to ensure the container exists;
do this once on application start up.
Constructors
Containers(Database, Client |
Properties
database |
Methods
create(Container |
Creates a container. A container is a named logical container for items. A database may contain zero or more named containers and each container consists of zero or more JSON items. Being schema-free, the items in a container do not need to share the same structure or fields. Since containers are application resources, they can be authorized using either the master key or resource keys. |
create |
Checks if a Container exists, and, if it doesn't, creates it.
This will make a read operation based on the id in the A container is a named logical container for items. A database may contain zero or more named containers and each container consists of zero or more JSON items. Being schema-free, the items in a container do not need to share the same structure or fields. Since containers are application resources, they can be authorized using either the master key or resource keys. |
query(Sql |
Queries all containers. Example Read all containers to array.
* |
query<T>(Sql |
Queries all containers. Example Read all containers to array.
* |
read |
Read all containers. Example Read all containers to array.
* |
Constructor Details
Containers(Database, ClientContext)
new Containers(database: Database, clientContext: ClientContext)
Parameters
- database
- Database
- clientContext
-
ClientContext
Property Details
database
Method Details
create(ContainerRequest, RequestOptions)
Creates a container.
A container is a named logical container for items.
A database may contain zero or more named containers and each container consists of zero or more JSON items.
Being schema-free, the items in a container do not need to share the same structure or fields.
Since containers are application resources, they can be authorized using either the master key or resource keys.
function create(body: ContainerRequest, options?: RequestOptions): Promise<ContainerResponse>
Parameters
- body
- ContainerRequest
Represents the body of the container.
- options
- RequestOptions
Use to set options like response page size, continuation tokens, etc.
Returns
Promise<ContainerResponse>
createIfNotExists(ContainerRequest, RequestOptions)
Checks if a Container exists, and, if it doesn't, creates it.
This will make a read operation based on the id in the body
, then if it is not found, a create operation.
You should confirm that the output matches the body you passed in for non-default properties (i.e. indexing policy/etc.)
A container is a named logical container for items.
A database may contain zero or more named containers and each container consists of zero or more JSON items.
Being schema-free, the items in a container do not need to share the same structure or fields.
Since containers are application resources, they can be authorized using either the master key or resource keys.
function createIfNotExists(body: ContainerRequest, options?: RequestOptions): Promise<ContainerResponse>
Parameters
- body
- ContainerRequest
Represents the body of the container.
- options
- RequestOptions
Use to set options like response page size, continuation tokens, etc.
Returns
Promise<ContainerResponse>
query(SqlQuerySpec, FeedOptions)
Queries all containers.
Example
Read all containers to array.
* typescript * const querySpec: SqlQuerySpec = { * query: "SELECT * FROM root r WHERE r.id = @container", * parameters: [ * {name: "@container", value: "Todo"} * ] * }; * const {body: containerList} = await client.database("<db id>").containers.query(querySpec).fetchAll(); *
function query(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<any>
Parameters
- query
- SqlQuerySpec
Query configuration for the operation. See SqlQuerySpec for more info on how to configure a query.
- options
- FeedOptions
Use to set options like response page size, continuation tokens, etc.
Returns
QueryIterator<any>
QueryIterator Allows you to return specific containers in an array or iterate over them one at a time. *
query<T>(SqlQuerySpec, FeedOptions)
Queries all containers.
Example
Read all containers to array.
* typescript * const querySpec: SqlQuerySpec = { * query: "SELECT * FROM root r WHERE r.id = @container", * parameters: [ * {name: "@container", value: "Todo"} * ] * }; * const {body: containerList} = await client.database("<db id>").containers.query(querySpec).fetchAll(); *
function query<T>(query: SqlQuerySpec, options?: FeedOptions): QueryIterator<T>
Parameters
- query
- SqlQuerySpec
Query configuration for the operation. See SqlQuerySpec for more info on how to configure a query.
- options
- FeedOptions
Use to set options like response page size, continuation tokens, etc.
Returns
QueryIterator Allows you to return specific containers in an array or iterate over them one at a time. *
readAll(FeedOptions)
Read all containers.
Example
Read all containers to array.
* typescript * const {body: containerList} = await client.database("<db id>").containers.readAll().fetchAll(); *
function readAll(options?: FeedOptions): QueryIterator<ContainerDefinition & Resource>
Parameters
- options
- FeedOptions
Use to set options like response page size, continuation tokens, etc.
Returns
QueryIterator Allows you to return all containers in an array or iterate over them one at a time. *