How to check document has exist a field


#1

How to check if document has exist a field. i mean like this:
{
Id: ‘12532’,
field: null
}
=> exist
{
Id: ‘12532’
}
=> not exist


#2

Hi,

I guess N1QL would be a better option for performing this type of requests,
refer: How to get particular field in couchbase document

-Sreekanth


#3

Hey @nguyenxvn,

You can do it with a subdocument operation. With the Java SDK it would look like this:

DocumentFragment<Lookup> result = bucket.lookupIn("id").exists("field").execute();
Boolean fieldExists = (Boolean) result.content(0);

#4

Thanks @graham.pople for your help but i want to get list of document that missing that field to do migrade job.


#5

Hi @sreeks. when i search with N1QL the server get high memory usage and all of my application on server stop working.
couchbase stop
elasticsearch stop
nodejs website stop too