Index creation
HCL OneDB™ supports the creation of indexes on collections and relational tables by using the MongoDB API and the wire listener.
Index creation by using the MongoDB syntax
For
JSON collections and relational tables, you can use the MongoDB createIndex
and ensureIndex syntax to create an index that works for all data
types. For example:
db.collection.createIndex( { zipcode: 1 } )
db.collection.createIndex( { state: 1, zipcode: -1} )
Tip: If you are creating an index for a JSON collection on a
field that has a fixed data type, you can get the best query performance
by using the HCL
OneDB extended
syntax.
The following options are supported:
- name
- unique
The following options are not supported:
- background
- default_language
- dropDups
- expireAfterSeconds
- language_override
- sparse
- v
- weights
Index creation for a specific data type by using the HCL OneDB extended syntax
You can use the HCL OneDB createIndex or ensureIndex syntax on collections to create an index for a specific data type. For example:db.collection.createIndex( { zipcode : [1, "$int"] } )
db.collection.createIndex( { state: [1, "$string"], zipcode: [-1, "$int"] } )
This
syntax is supported for collections only. It not supported for relational tables.Tip: If you are creating an index on a field that has a fixed data type, you
can get better query performance by using the HCL
OneDB extended syntax.
The following data types are supported:
- $bigint
- $binary
- $boolean
- $date
- $double2
- $int3
- $integer3
- $lvarchar1
- $number2
- $string1
- $timestamp
- $varchar
Notes:
- $string and $lvarchar are aliases and create lvarchar indexes.
- $number and $double are aliases and create double indexes.
- $int and $integer are aliases.
Index creation for arrays using the Informix extended syntax
You can use the HCL OneDB createIndex or ensureIndex syntax on collections to create an index for arrays. For example:db.collection.createIndex( { "my_array" : [ 1, "$array", "$int" ] } )
which
creates an integer array index on the field named "my_array".This syntax is similar to the Informix extended typed syntax. Specify the type of the index as "$array" and then provide a third argument specifying the data type stored in the array.
Note: This syntax is supported for
collections only. It is not supported for relational tables.
Index creation for text, geospatial, and hashed
- Text indexes
- Text indexes are supported. You can search string content by using text search in documents of a collection.
- Geospatial indexes
- 2dsphere indexes are supported in HCL OneDB by using the GeoJSON objects, but not the MongoDB legacy coordinate pairs.
- Hashed indexes
- Hashed indexes are not supported. If a hashed index is specified, a regular untyped index is created.
For more information about the MongoDB features, see http://docs.mongodb.org/manual/reference/.