mirror of https://gitee.com/bigwinds/arangodb
47 lines
1.9 KiB
Plaintext
47 lines
1.9 KiB
Plaintext
!CHAPTER JavaScript Interface to Collections
|
|
|
|
This is an introduction to ArangoDB's interface for collections and how to handle
|
|
collections from the JavaScript shell _arangosh_. For other languages see the
|
|
corresponding language API.
|
|
|
|
The most important call is the call to create a new collection.
|
|
|
|
!SECTION Address of a Collection
|
|
|
|
All collections in ArangoDB have a unique identifier and a unique
|
|
name. ArangoDB internally uses the collection's unique identifier to look up
|
|
collections. This identifier, however, is managed by ArangoDB and the user has
|
|
no control over it. In order to allow users to use their own names, each collection
|
|
also has a unique name which is specified by the user. To access a collection
|
|
from the user perspective, the [collection name](../Glossary/README.md#collection-name) should be used, i.e.:
|
|
|
|
!SUBSECTION Collection
|
|
`db._collection(collection-name)`
|
|
|
|
A collection is created by a ["db._create"](../Collections/DatabaseMethods.md) call.
|
|
|
|
For example: Assume that the [collection identifier](../Glossary/README.md#collection-identifier) is *7254820* and the name is
|
|
*demo*, then the collection can be accessed as:
|
|
|
|
db._collection("demo")
|
|
|
|
If no collection with such a name exists, then *null* is returned.
|
|
|
|
There is a short-cut that can be used for non-system collections:
|
|
|
|
!SUBSECTION Collection name
|
|
`db.collection-name`
|
|
|
|
This call will either return the collection named *db.collection-name* or create
|
|
a new one with that name and a set of default properties.
|
|
|
|
**Note**: Creating a collection on the fly using *db.collection-name* is
|
|
not recommend and does not work in _arangosh_. To create a new collection, please
|
|
use
|
|
|
|
!SUBSECTION Create
|
|
`db._create(collection-name)`
|
|
|
|
This call will create a new collection called *collection-name*.
|
|
This method is a database method and is documented in detail at [Database Methods](../Collections/DatabaseMethods.md#create)
|