mirror of https://gitee.com/bigwinds/arangodb
201 lines
6.6 KiB
Plaintext
201 lines
6.6 KiB
Plaintext
!CHAPTER Creating and Deleting Collections
|
|
|
|
`POST /_api/collection`*(creates a collection)*
|
|
|
|
!SUBSECTION Body parameters
|
|
|
|
`body (json,required)`
|
|
|
|
the body with name and options for a collection.
|
|
|
|
!SUBSECTION Description
|
|
|
|
Creates an new collection with a given name. The request must contain an object with the following attributes.
|
|
|
|
* name: The name of the collection.
|
|
* waitForSync (optional, default: false): If true then the data is synchronised to disk before returning from a create or update of a document.
|
|
* doCompact (optional, default is true): whether or not the collection will be compacted.
|
|
* journalSize (optional, default is a configuration parameter): The maximal size of a journal or datafile. Note that this also limits the maximal size of a single object. Must be at least 1MB.
|
|
* isSystem (optional, default is false): If true, create a system collection. In this case collection-name should start with an underscore. End users should normally create non-system collections only. API implementors may be required to create system collections in very special occasions, but normally a regular collection will do.
|
|
* isVolatile (optional, default is false): If true then the collection data is kept in-memory only and not made persistent. Unloading the collection will cause the collection data to be discarded. Stopping or re-starting the server will also cause full loss of data in the collection. Setting this option will make the resulting collection be slightly faster than regular collections because ArangoDB does not enforce any synchronisation to disk and does not calculate any CRC checksums for datafiles (as there are no datafiles).
|
|
|
|
This option should threrefore be used for cache-type collections only, and not for data that cannot be re-created otherwise.
|
|
|
|
keyOptions (optional) additional options for key generation. If specified, then keyOptions should be a JSON array containing the following attributes (note: some of them are optional):
|
|
|
|
* type: specifies the type of the key generator. The currently available generators are traditional and autoincrement.
|
|
* allowUserKeys: if set to true, then it is allowed to supply own key values in the _key attribute of a document. If set to false, then the key generator will solely be responsible for generating keys and supplying own key values in the _key attribute of documents is considered an error.
|
|
* increment: increment value for autoincrement key generator. Not used for other key generator types.
|
|
* offset: initial offset value for autoincrement key generator. Not used for other key generator types.
|
|
* type (optional, default is 2): the type of the collection to create. The following values for type are valid:
|
|
* 2: document collection
|
|
* 3: edges collection
|
|
* numberOfShards (optional, default is 1): in a cluster, this value determines the number of shards to create for the collection. In a single server setup, this option is meaningless.
|
|
* shardKeys (optional, default is [ "_key" ]): in a cluster, this attribute determines which document attributes are used to determine the target shard for documents. Documents are sent to shards based on the values of their shard key attributes. The values of all shard key attributes in a document are hashed, and the hash value is used to determine the target shard. Note that values of shard key attributes cannot be changed once set. This option is meaningless in a single server setup.
|
|
|
|
*Examples*
|
|
|
|
```
|
|
unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/collection
|
|
{"name":"testCollectionBasics"}
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json; charset=utf-8
|
|
location: /_db/_system/_api/collection/testCollectionBasics
|
|
|
|
{
|
|
"id" : "21816289",
|
|
"name" : "testCollectionBasics",
|
|
"waitForSync" : false,
|
|
"isVolatile" : false,
|
|
"isSystem" : false,
|
|
"status" : 3,
|
|
"type" : 2,
|
|
"error" : false,
|
|
"code" : 200
|
|
}
|
|
|
|
unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/collection
|
|
{"name":"testCollectionEdges","type":3}
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json; charset=utf-8
|
|
location: /_db/_system/_api/collection/testCollectionEdges
|
|
|
|
{
|
|
"id" : "21881825",
|
|
"name" : "testCollectionEdges",
|
|
"waitForSync" : false,
|
|
"isVolatile" : false,
|
|
"isSystem" : false,
|
|
"status" : 3,
|
|
"type" : 3,
|
|
"error" : false,
|
|
"code" : 200
|
|
}
|
|
|
|
unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/collection
|
|
{"name":"testCollectionUsers","keyOptions":{"type":"autoincrement","increment":5,"allowUserKeys":true}}
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json; charset=utf-8
|
|
location: /_db/_system/_api/collection/testCollectionUsers
|
|
|
|
{
|
|
"id" : "21947361",
|
|
"name" : "testCollectionUsers",
|
|
"waitForSync" : false,
|
|
"isVolatile" : false,
|
|
"isSystem" : false,
|
|
"status" : 3,
|
|
"type" : 2,
|
|
"error" : false,
|
|
"code" : 200
|
|
}
|
|
```
|
|
|
|
`DELETE /_api/collection/{collection-name}`*(deletes a collection)*
|
|
|
|
!SUBSECTION URL parameters
|
|
|
|
`collection-name (string,required)`
|
|
|
|
The name of the collection to delete.
|
|
|
|
!SUBSECTION Description
|
|
|
|
Deletes a collection identified by collection-name.
|
|
|
|
If the collection was successfully deleted then, an object is returned with the following attributes:
|
|
|
|
* error: false
|
|
* id: The identifier of the deleted collection.
|
|
|
|
!SUBSECTION Return codes
|
|
|
|
`HTTP 400`
|
|
|
|
If the collection-name is missing, then a HTTP 400 is returned.
|
|
|
|
`HTTP 404`
|
|
|
|
If the collection-name is unknown, then a HTTP 404 is returned.
|
|
|
|
*Examples*
|
|
|
|
Using an identifier:
|
|
|
|
```
|
|
unix> curl -X DELETE --dump - http://localhost:8529/_api/collection/44491745
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json; charset=utf-8
|
|
|
|
{
|
|
"id" : "44491745",
|
|
"error" : false,
|
|
"code" : 200
|
|
}
|
|
```
|
|
|
|
Using a name:
|
|
|
|
```
|
|
unix> curl -X DELETE --dump - http://localhost:8529/_api/collection/products1
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json; charset=utf-8
|
|
|
|
{
|
|
"id" : "44557281",
|
|
"error" : false,
|
|
"code" : 200
|
|
}
|
|
```
|
|
|
|
`PUT /_api/collection/{collection-name}/truncate`*(truncates a collection)*
|
|
|
|
!SUBSECTION URL parameters
|
|
|
|
`collection-name (string,required)`
|
|
|
|
The name of the collection.
|
|
|
|
!SUBSECTION Description
|
|
|
|
Removes all documents from the collection, but leaves the indexes intact.
|
|
|
|
*Examples*
|
|
|
|
```
|
|
unix> curl -X PUT --dump - http://localhost:8529/_api/collection/43705313/truncate
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json; charset=utf-8
|
|
|
|
{
|
|
"id" : "43705313",
|
|
"name" : "products",
|
|
"isSystem" : false,
|
|
"status" : 3,
|
|
"type" : 2,
|
|
"error" : false,
|
|
"code" : 200
|
|
}
|
|
```
|
|
|
|
|
|
<!--
|
|
@anchor HttpCollectionCreate
|
|
@copydetails JSF_post_api_collection
|
|
|
|
@CLEARPAGE
|
|
@anchor HttpCollectionDelete
|
|
@copydetails JSF_delete_api_collection
|
|
|
|
@CLEARPAGE
|
|
@anchor HttpCollectionTruncate
|
|
@copydetails JSF_put_api_collection_truncate
|
|
|
|
@CLEARPAGE
|
|
--> |