Hello All,
following are my document structure and I have to query in CB DB for the fields in where condition for DeptCode/RoleCode. I am new early reply is much appreciable.
I am really looking for above document type solution. proposed solution will not work. Please also tell me can we apply meta().id along with unnest. Kindly revert
What is your expected output? The query proposed earlier should work. you mentioned it doesn’t work and did not say why?
If your bucket is default and document id is “RolePermissions”
SELECT d.*
FROM default AS d USE KEYS ["RolePermissions"];
If you want extract DeptCode, RoleCode when DocType = “Role Permission Document” from original document as array of objects
SELECT ARRAY {v.DeptCode, v.RoleCode} FOR v IN d WHEN v.DocType = "Role Permission Document" END AS newdoc
FROM default AS d USE KEYS ["RolePermissions"];
If you want extract DeptCode, RoleCode when DocType = “Role Permission Document” from original document as separate documents
SELECT du.DeptCode, du.RoleCode
FROM default AS d USE KEYS ["RolePermissions"]
UNNEST d AS du
WHERE du.DocType = "Role Permission Document" ;
my working query
SELECT du.* FROM APTCREF AS d USE KEYS[‘RolePermissions’]
UNNEST d.RolePermission AS du where du.DeptCode = ‘FOE’ AND du.RoleCode = ‘HOD’