Details
-
Bug
-
Resolution: Fixed
-
Test Blocker
-
None
-
None
-
*Location*: https://docs.couchbase.com/python-sdk/3.0/hello-world/start-using-sdk.html
*User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
*Screen Resolution*: 2048 x 1080
-
DOC-2020-S14-Jul26
-
1
Description
The example on the page needs to be updated to work with Couchbase 6.5 and Python SDK 3.0. With help from Ellis I was able to get a version that works. He asked me to file a ticket to track updating the docs.
from couchbase.cluster import Cluster, ClusterOptions, QueryOptions |
from couchbase_core.cluster import PasswordAuthenticator |
|
cluster = Cluster('couchbase://localhost:12000', ClusterOptions(PasswordAuthenticator('Administrator', 'asdasd'))) |
cb = cluster.bucket('bucket-name') |
cb_coll = cb.default_collection() |
cb_coll.upsert('u:king_arthur', |
{'name': 'Arthur', 'email': 'kingarthur@couchbase.com', 'interests': ['Holy Grail', 'African Swallows']}) |
# OperationResult<RC=0x0, Key=u'u:king_arthur', CAS=0xb1da029b0000>
|
|
print(cb_coll.get('u:king_arthur').content_as[str]) |
# {u'interests': [u'Holy Grail', u'African Swallows'], u'name': u'Arthur', u'email': u'kingarthur@couchbase.com'}
|
|
## The CREATE PRIMARY INDEX step is only needed the first time you run this script
|
# cluster.query('CREATE PRIMARY INDEX ON `bucket-name` using GSI;')
|
cluster.query_indexes().create_primary_index('bucket-name') |
|
from couchbase_core.n1ql import N1QLQuery |
row_iter = cluster.query('SELECT name FROM `bucket-name` WHERE $1 IN interests', |
QueryOptions(positional_parameters=['African Swallows'])) |
for row in row_iter: |
print(row) |
# {u'name': u'Arthur'} |