This is an introduction to ArangoDB's interface for indexs in general. There are special sections for cap constraints, geo-spatial indexes, hash indexes, and skip-lists.
Index: Indexes are used to allow fast access to documents. For each collection there is always the primary index which is a hash index for the document identifier.
Index Handle: An index handle uniquely identifies an index in the database. It is a string and consists of a collection identifier and a index identifier separated by /
.
Geo Index: A geo index is used to find places on the surface of the earth fast.
Hash Index: A hash index is used to find documents based on examples.
Skiplist Index: A skiplist is used to find ranges of documents.
All indexs in ArangoDB have an index handle. This handle uniquely defines an index and is managed by ArangoDB. The interface allows you to access the indexs of a collection as:
db.collection.index(index-handle)
For example: Assume that the index handle, which is stored in the _id
field of the index, is 7254820/362549736
and the index lives in a collection named demo, then that index can be accessed as:
db.demo.index("7254820/362549736")
Because the index handle is unique within the database, you can leave out the collection and use the shortcut:
db._index("7254820/362549736")
collection.index(index-handle)
Examples
arango> db.example.getIndexes().map(function(x) { return x.id; }); ["93013/0"] arango> db.example.index("93013/0"); { "id" : "93013/0", "type" : "primary", "fields" : ["_id"] }
getIndexes()
Examples
arango> db.demo.getIndexes() [ { "id" : "1439003/0", "type" : "primary", "fields" : ["_id"] }, { "id" : "1439003/2290971", "unique" : true, "type" : "hash", "fields" : ["a"] }, { "id" : "1439003/2946331", "unique" : false, "type" : "hash", "fields" : ["b"] }, { "id" : "1439003/3077403", "unique" : false, "type" : "skiplist", "fields" : ["c"] } ]
collection.dropIndex(index)
false
is returned. If the index existed and was dropped, then true
is returned. Note that you cannot drop the primary index.
collection.dropIndex(index-handle)
Examples
arango> db.example.ensureSkiplist("a", "b"); { "id" : "73650/991154", "unique" : false, "type" : "skiplist", "fields" : ["a", "b"], "isNewlyCreated" : true } arango> i = db.example.getIndexes(); [{ "id" : "73650/0", "type" : "primary", "fields" : ["_id"] }, { "id" : "73650/991154", "unique" : false, "type" : "skiplist", "fields" : ["a", "b"] }] arango> db.example.dropIndex(i[0]) false arango> db.example.dropIndex(i[1].id) true arango> i = db.example.getIndexes(); [{ "id" : "73650/0", "type" : "primary", "fields" : ["_id"] }]
db._index(index-handle)
Examples
arango> db.example.getIndexes().map(function(x) { return x.id; }); ["93013/0"] arango> db._index("93013/0"); { "id" : "93013/0", "type" : "primary", "fields" : ["_id"] }
db._dropIndex(index)
false
is returned. If the index existed and was dropped, then true
is returned. Note that you cannot drop the primary index.
db._dropIndex(index-handle)
Examples
arango> db.example.ensureSkiplist("a", "b"); { "id" : "73650/1577138", "unique" : false, "type" : "skiplist", "fields" : ["a", "b"], "isNewlyCreated" : true } arango> i = db.example.getIndexes(); [{ "id" : "73650/0", "type" : "primary", "fields" : ["_id"] }, { "id" : "73650/1577138", "unique" : false, "type" : "skiplist", "fields" : ["a", "b"] }] arango> db._dropIndex(i[0]); false arango> db._dropIndex(i[1].id); true arango> i = db.example.getIndexes(); [{ "id" : "73650/0", "type" : "primary", "fields" : ["_id"] }]