'db._index(index-handle)' method get an index by handle, if no index exist with given handle it returns null.
Let’s try it with an example.
127.0.0.1:8529@abc_org> db.employees.getIndexes() [ { "fields" : [ "_key" ], "id" : "employees/0", "name" : "primary", "selectivityEstimate" : 1, "sparse" : false, "type" : "primary", "unique" : true }, { "deduplicate" : true, "fields" : [ "firstName", "lastName" ], "id" : "employees/648", "name" : "firstNameLastNameIndex", "selectivityEstimate" : 1, "sparse" : false, "type" : "persistent", "unique" : false } ]
As you see above snippet, employees collection has two indexes. Let’s get firstNameLastNameIndex using the handle "employees/648".
127.0.0.1:8529@abc_org> indexForName = db._index("employees/648") { "deduplicate" : true, "fields" : [ "firstName", "lastName" ], "id" : "employees/648", "name" : "firstNameLastNameIndex", "sparse" : false, "type" : "persistent", "unique" : false, "code" : 200 }
Once you got index handle, you can access the index properties using ‘.’ operator.
127.0.0.1:8529@abc_org> indexForName.fields [ "firstName", "lastName" ] 127.0.0.1:8529@abc_org> indexForName.code 200
No comments:
Post a Comment