I am using couchbase enterprise 7.1, I have JSON documents stored in couchbase collection and each document is softlinked to each other with parent child relationship being established using customId.
here docId is meta().id
example s
@gotroyilmi, since CB doesn’t support explicit foreign keys (schema-less), you have to use a solution such as the Eventing example I provided. Conceptually it is still a “cascading delete based on a foreign key” - just you’re defining “foreign key” (in the Eventing function code) rather than the DB (schema) defining it, and making use of the Eventing service to automate the deletion.
Because you’re passing $1 as an argument, it isn’t expanded in-line to be interpreted as part of the query string.
You don’t need any of the quoting with parameters; it can detect you’ve passed an array of strings and will deal with them appropriately.
So try:
var queryParamIds = Array.from(idSet)
log("queryParamIds : " + queryParamIds);
var results = N1QL("SELECT c.customId, meta().id " +
"FROM `bucket-name`.`scope-name`.`collection-name` AS tbl " +
"WHERE tbl.docCategory = \"C\" " +
"AND (ANY v IN ( " +
" SELECT DISTINCT customId AS customId" +
" FROM `bucket-name`.`scope-name`.`collection-name` AS tbl_a" +
" WHERE tbl_a.docCategory = \"C\" " +
" AND ANY x IN relationship.parents SATISFIES x.customId IN $1 END" +
") SATISFIES v.customId = tbl.customId END);",
[queryParamIds],
{'isPrepared': true}
);
Alternatively you could expand into string constants within pure JS code and not pass a parameter (that said, typically we’d recommend a parameter for data that isn’t likely to be constant across invocations).