Hi there,
I took a two-step approach for this:
First of all, as there is no pre-defined addToSet function, I registered
an AQL user function named "my::addToSet" via the ArangoShell:
var aqlfunctions = require("org/arangodb/aql/functions");
var addToSet = function (previous, toAdd) {
if (previous === undefined ||
previous === null ||
! Array.isArray(previous)) {
/* initial value for the set */
return [ toAdd ];
}
/* compare each existing element against toAdd */
var compare = JSON.stringify(toAdd);
for (var i = 0; i < previous.length; ++i) {
if (JSON.stringify(previous[i]) === compare) {
/* toAdd is already in the set */
return previous;
}
}
/* toAdd is not yet in the set. now add it */
previous.push(toAdd);
return previous;
});
aqlfunctions.register("my::addToSet", addToSet);
After that, the function is callable from AQL via my::addToSet(), for
example using this query:
FOR p IN profiles
FILTER p.doc == @doc && p._key == @key
LET contacts = my::addToSet(p.detail.cnx.e, @data)
LET detail = { cnx: { e: contacts } }
UPDATE p WITH {detail: detail} IN profiles
I used the following bind parameters to call it:
{
"doc": "profile",
"key": "81855392035",
"data": {
"name": "John Doe",
"at": "
pe...@test.com",
"type": "private3"
}
}
I think this does what was required. Please let me know if this is
working for you.
Thank you and best regards
Jan
> --
> You received this message because you are subscribed to the Google
> Groups "ArangoDB" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
arangodb+u...@googlegroups.com
> <mailto:
arangodb+u...@googlegroups.com>.
> For more options, visit
https://groups.google.com/d/optout.