Hello,
I just started using python sdk to interact with couchbase db.
I could use cbq to create a primary index on collection as follows:
CREATE PRIMARY INDEX ON test.test_scope.test_collection;
where test is the bucket, test_scope is the scope and test_collection is the collection in my db.
However using python sdk with the following codes, I could not create the same primary index, maybe the syntax is incorrect, however I couldn’t find relevant instructions from the python couchbase documentation. Hopefully someone can point me to the correct direction to fix this out.
from couchbase.cluster import Cluster, ClusterOptions
from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import QueryOptions
from couchbase.management.queries import CreatePrimaryQueryIndexOptions
Hi @mzw - The Python SDK does not support index management for collections yet. See the ticket here for tracking the implementation of index management for collections.
In the interim, you can create a query to add indexes with collections. See an example below.
cluster.query(
"CREATE PRIMARY INDEX ON `{}`.`{}`.{}".format("travel-sample","inventory","airport")).execute()