Creating a Collection
Collections can be created by means of the REST API.
Collections are created by means of the
POST /pools/default/buckets/<bucket_name>/scopes/<scope_name>/collections HTTP method and URI.
The curl syntax is as follows:
curl -X POST -u [admin]:[password] http://<hostname-or-ip>:8091/pools/default/buckets/\ <bucket_name>/scopes/<scope-name>/collections -d name=<collection-name> -d maxTTL=[integer]
<bucket-name> path-parameter specifies the name of the bucket within which the new collection is to reside.
<scope-name> path-parameter provides the name of the scope within which the new collection is to reside.
name parameter specifies the name of the collection to be created: this name cannot subsequently be changed.
maxTTL flag can be used to specify an expiration value for the collection: the specified value must be an integer representing seconds; with the maximum permissible value being 2147483648 (or 68.096 years).
The default value for
0, which disables TTL for the collection.
For more information, see Expiration.
Failure to authenticate gives
A malformed URI fails with
404 Object Not Found.
If the collection-name is improperly specified, a notification such as
"name":"Length must be in range from 1 to 30" or
"name":"Can only contain characters A-Z, a-z, 0-9 and the following symbols _ - %" is displayed.
See Naming for Scopes and Collections, for an account of naming conventions.
The following call creates a collection named
my_collection_in_my_scope, within an existing scope named
my_scope, and specifies an expiration value in seconds that is equivalent to two years:
curl -X POST -v -u Administrator:password \ http://10.143.210.101:8091/pools/default/buckets/\ testBucket/scopes/my_scope/collections \ -d name=my_collection_in_my_scope_1 \ -d maxTTL=63113904
If successful, the call returns a
uid, such as the following: