Skip to content

Instantly share code, notes, and snippets.

@alicek106
Created March 25, 2020 01:59
Show Gist options
  • Save alicek106/626530ff820029206d16e27ddbcad8ce to your computer and use it in GitHub Desktop.
Save alicek106/626530ff820029206d16e27ddbcad8ce to your computer and use it in GitHub Desktop.
from couchbase.cluster import Cluster
from couchbase.cluster import PasswordAuthenticator
cluster = Cluster('couchbase://couchbase')
authenticator = PasswordAuthenticator('admin', 'testpassword')
# from couchbase.admin import Admin
# adm = Admin('admin', 'testpassword', host='couchbase', port=8091)
# adm.bucket_create('alice-bucket-test', bucket_type='couchbase')
cluster.authenticate(authenticator)
cb = cluster.open_bucket('alicek106-test')
for i in range(1000):
cb.upsert('u:alice{}'.format(i), {'name': 'alice', 'data':i })
# {u'interests': [u'Holy Grail', u'African Swallows'], u'name': u'Arthur', u'email': u'[email protected]'}
## The CREATE PRIMARY INDEX step is only needed the first time you run this script
# cb.n1ql_query('CREATE PRIMARY INDEX ON bucket-name').execute()
# from couchbase.n1ql import N1QLQuery
# row_iter = cb.n1ql_query(N1QLQuery('SELECT name FROM bucket-name WHERE ' +\
# '$1 IN interests', 'African Swallows'))
# for row in row_iter: print(row)
# {u'name': u'Arthur'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment