I know that I can use a get to get a specific field of a document BUT what if I use a get to get the entire document but then want to access a specific field?
so I do a get and then print the rv.value
which displays below:
{‘mName’: ‘’, ‘addr1’: ‘130333 575 Proudfoot Lane’, ‘lName’: ‘Bonilla M’, ‘city’: ‘London’, ‘fName’: ‘Guillermo’}
is it now possible to get the value of fName from the rv object?
I know that I can do
rv = cb.lookup_in(custId, SD.get(‘fName’))
but I would like to retrieve the entire document and then look at several fields, I would think it should be possible to get the entire document and the extract whatever fields I want, the document seems to hint that this is possible but I cannot seem to figure out how. Any help is appreciated.
The value attribute of the result is (as the name suggests) the value of the document.
This is stored as a native python dictionary (assuming that the document is JSON) and so all of the fields can be accessed in the same way as any normal dictionary.
How does this work fo a NQL query.
eg
query_string = “select META().id as metaid, t.* from ice_us t where META().id !=‘sdfdsf’ limit 10”
q = N1QLQuery(query_string)
for eachrow in cb.n1ql_query(q):
docid=eachrow.value[‘metaid’]
print (docid)
Traceback (most recent call last):
File “C:/Users/fakj/PycharmProjects/COUCHBASE/couchbase_lab_load.py”, line 33, in
docid=eachrow.value[‘metaid’]
AttributeError: ‘dict’ object has no attribute ‘value’