Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-6203

Python SDK hello-world needs updating for SDK 3.0

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Test Blocker
    • None
    • None

    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'}
      

      Attachments

        Activity

          People

            richard.smedley Richard Smedley
            steve.watanabe Steve Watanabe
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              PagerDuty