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
    • Status: Closed
    • Test Blocker
    • Resolution: Fixed
    • 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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          steve.watanabe Steve Watanabe created issue -
          richard.smedley Richard Smedley made changes -
          Field Original Value New Value
          Assignee Amarantha Kulkarni [ amarantha.kulkarni ] Richard Smedley [ richard smedley ]
          richard.smedley Richard Smedley made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          steve.watanabe Steve Watanabe made changes -
          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&#39;, 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'}
          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.
          {code:python}
          from couchbase.cluster import Cluster, ClusterOptions, QueryOptions
          from couchbase_core.cluster import PasswordAuthenticator

          cluster = Cluster('couchbase://localhost:12000&#39;, 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'}
          {code}
          richard.smedley Richard Smedley made changes -
          Component/s sdk [ 14110 ]
          richard.smedley Richard Smedley made changes -
          Labels collector-de2e9313 collector-de2e9313 python sdk3
          richard.smedley Richard Smedley made changes -
          Rank Ranked higher
          richard.smedley Richard Smedley made changes -
          Status In Progress [ 3 ] Open [ 1 ]
          brett19 Brett Lawson made changes -
          Story Points 1
          richard.smedley Richard Smedley made changes -
          Component/s server dev guide and SDKs [ 11814 ]
          Component/s sdk [ 14110 ]
          Sprint DOC-2020-S13-Jul12 [ 1115 ]
          Priority Test Blocker [ 6 ]
          richard.smedley Richard Smedley made changes -
          Sprint DOC-2020-S13-Jul12 [ 1115 ] DOC-2020-S14-Jul26 [ 1127 ]
          richard.smedley Richard Smedley made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          richard.smedley Richard Smedley made changes -
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Resolved [ 5 ]
          steve.watanabe Steve Watanabe made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

          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:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty