is the standard way in N1QL to refer to field names that have special characters in them, such as space or dash (’ ’ or ‘-’). I suspect that the node.js SDK doesn’t like a numeric field name, hence the need for back-ticks.
The result of result.content('a.150') is null if exists and exception if not exists but result.exists('a.150') is true/false , Is it a good behavior? If I want to check existence of a field I must do bucket.lookupIn.exists the result.exists
It’s worth recognizing that you can call the exists(...) method on your result object to determine if a value existed after executing a get(...) operation for the lookup. Using the request-time exists operation itself is primarily useful as an optimization when the existence of an element is important, but its specific value is not.
Using the request-time exists operation itself is primarily useful as an optimization when the existence of an element is important, but its specific value is not.
Both of those are more or less identical in their behaviour. Typically I prefer to rely on the exists method as handling a boolean is simpler than catching an exception, but both are going to give the same results. I’d say to base it around your use-case. If the element not being found is a fatal error, simply use .content(...) and allow it to fail, alternatively if it missing is a standard case and you wish to handle it, you can check first using .exists(...).
FYI, I checked the N1QL parser, and unless you enclose a field name in back ticks, the name must start with a letter on underscore. Thus ‘a.150’ should not be valid, you need to enclose 150 in back ticks.
The lookupIn method is using an API called ‘sub-document operations’ that the SDKs support. The grammar for referencing fields in sub-document is slightly different than that of referencing fields in N1QL. That’s the reason for the difference in needing the backticks or not.