Data Example
{
“userId”: 1,
“firstName”: “AAAAA”,
“lastName”: “as23”,
“phoneNumber”: “123456”,
“emailAddress”: “AAAAA@test.com”,
“homepage”: “https://aaaaaa.aaaaa.com/1”
}
I want to select firstName, lastName, phoneNumber only. Through Python SDK lookup_in
res = collection.lookup_in(key, (SD.get(“firstName”), SD.get("lastName), SD.get("phoneNumber)))
This possible to make a choice in the a way?
Yes. There is an example here
bellpumpkin
1
16m
res = collection.lookup_in(key, (SD.get(“firstName”), SD.get("lastName), SD.get("phoneNumber)))
How to print keys and value
I want to get a result like A.
A: {“firstName”: “AAAAA”, “lastName”: “as23”, “phoneNumber”: “123456”}
The current value is AAAAA.
There’s only one.
I can’t even see KEY.
The key isn’t in the document. And you need to specify it to get the document, so you already have it.
Also - the example has the result indexed with (0), because it only retries 1 property. So if you’re indexing the result with (0), you’ll only see the first property as well.
from datetime import timedelta
import couchbase.subdocument as SD
from couchbase.options import LookupInOptions
# ... other code ...
key = 'hotel_10025'
res = collection.lookup_in(key,
(SD.get("geo"),),
LookupInOptions(timeout=timedelta(seconds=2)))
print(f'Hotel {key} coordinates: {res.content_as[dict](0)}')