I am storing all my Doc edits with the GUID of the user who did them. Thats all great but here comes the issue, The actual end user who is looking at the audit trail has no idea. Also as some backend is SQL the userid i use are basec UID without a prefix, but in couchbase i store them as user::GUID
So i use the blow query to get the user name based on the guid which works great
select referenceId,history.created_by,
(select name.fname || " " || name.lname as created_by_name from Contacts USE KEYS "user::" || c.history.created_by) from Contacts c
where _type="task" and referenceId = "contact::b15ca89b-8d14-4e83-8d7e-ed9bad71c773"
select referenceId,history.created_by,
(select RAW name.fname || " " || name.lname from Contacts USE KEYS "user::" || c.history.created_by)[0] AS created_by_name from Contacts c
where _type="task" and referenceId = "contact::b15ca89b-8d14-4e83-8d7e-ed9bad71c773"
what i am looking for is to be able to get the raw
(select RAW name.fname || " " || name.lname from Contacts USE KEYS "user::" || c.history.created_by)[0] AS created_by_name
"created_by_name": "John Doe"
select referenceId,
OBJECT_ADD(history, "created_by_name", (select RAW name.fname || " " || name.lname from Contacts USE KEYS "user::" || c.history.created_by)[0]) AS history
from Contacts c
where _type="task" and referenceId = "contact::b15ca89b-8d14-4e83-8d7e-ed9bad71c773"
So i got the OBJECT_ADD to work if i want to only add one Object to my DOC but what happens wen in my case i want 2 or more ? Like the name of the created and the name of the update ?
OBJECT_ADD(history, "created_by_name", (select RAW name.fname || " " || name.lname from Contacts USE KEYS "user::" || c.history.created_by)[0]) as history,
OBJECT_ADD(history, "updated_by_name", (select RAW name.fname || " " || name.lname from Contacts USE KEYS "user::" || c.history.updated_by)[0]) as history,
if i do that i get the error “msg”: “Duplicate result alias history.”, if i change history to another name it works again but then i have 2 subdocs each with one added object ?
Is there a way to push more then one Objects into doc ?
SELECT referenceId,
OBJECT_CONCAT(history,
{"created_by_name": (SELECT RAW name.fname || " " || name.lname
FROM Contacts USE KEYS "user::" || c.history.created_by)[0],
"updated_by_name": (SELECT RAW name.fname || " " || name.lname
FROM Contacts USE KEYS "user::" || c.history.updated_by)[0]
}) AS history
FROM Contacts c
WHERE _type="task" AND referenceId = "contact::b15ca89b-8d14-4e83-8d7e-ed9bad71c773";