Can't get() doc which is kind of { '0': 'bla-bla', '1': 123 }


#1

Hello guys. I’m suddenly get to the trap with such kind of doc structure:
{ "0": "12233", "1": [ "d29e03687fb7bf79dc6035451e074c71e78c3404"] }
Simple I can’t get() it. I’m using couchbase@2.1.3 and result is: err=null, value=empty obj.

When I change decimal doc keys to text keys - doc resolved normally. I can’t change original doc structure, so i need to figure out how to resolve this kind of doc. Any ideas?


#2

Hey @tuiteraz,

Can you tell me how you inserted the document, and whether what you pasted above is the exact document as stored in Couchbase? I have inserted a document with the exact contents as pasted above and

null { cas: CouchbaseCas<121446074749440>,
  value: 
   { '0': '12233',
     '1': [ 'd29e03687fb7bf79dc6035451e074c71e78c3404' ] } }

Cheers, Brett


#3

During writing this example suddenly I’ve figured out that value is not shown in WebStrom debugger but actually is assigned to query result. It was completelly not obvious issue ( Sorry 8)

'use strict'
var couchbase = require('couchbase')
var cluster = new couchbase.Cluster('couchbase://127.0.0.1')
var bucket = cluster.openBucket('default')

const payload = '{"0":"12233","1":[["d29e03687fb7bf79dc6035451e074c71e78c3404",0,2,"3213232","2015-09-28 09:34:37"]],"5":["2,5,i,2,5,u,2,5,b"]}'
const payloadJson = JSON.parse(payload)

bucket.upsert('dec-keys-test', payloadJson, (err, res) => {
  bucket.get('dec-keys-test', (err, res) => {
    if (err) throw err
    console.log(res.value)
  })
})