So I'm trying to check to see if a value exists in an array on a node and then if it doesn't add it.
Example: check if 'c' is present in (node {array:['a','b']}) and if not add it (node {array:['a','b','c']}).
I get the feeling with the various functions that I can iterate through the array and use regular expressions to test each value but how do I then push a new value into the array?
I'm pretty sure I could split it into 2 queries but one would be better.
I'm going to experiment in the console but if anybody has already solved this problem I'd love to see.
So turns out adding to an array is easy, "SET node.array = node.array + value", however I can't figure out how to conditionally create the array property if it doesn't exist without splitting this into 2 queries.
On Friday, June 29, 2012 3:55:49 PM UTC-7, Mat Tyndall wrote:
> So I'm trying to check to see if a value exists in an array on a node and > then if it doesn't add it.
> Example: check if 'c' is present in (node {array:['a','b']}) and if not > add it (node {array:['a','b','c']}).
> I get the feeling with the various functions that I can iterate through > the array and use regular expressions to test each value but how do I then > push a new value into the array?
> I'm pretty sure I could split it into 2 queries but one would be better.
> I'm going to experiment in the console but if anybody has already solved > this problem I'd love to see.
> So turns out adding to an array is easy, "SET node.array = node.array + value", however I can't figure out how to conditionally create the array property if it doesn't exist without splitting this into 2 queries.
> On Friday, June 29, 2012 3:55:49 PM UTC-7, Mat Tyndall wrote:
> So I'm trying to check to see if a value exists in an array on a node and then if it doesn't add it.
> Example: check if 'c' is present in (node {array:['a','b']}) and if not add it (node {array:['a','b','c']}).
> I get the feeling with the various functions that I can iterate through the array and use regular expressions to test each value but how do I then push a new value into the array?
> I'm pretty sure I could split it into 2 queries but one would be better.
> I'm going to experiment in the console but if anybody has already solved this problem I'd love to see.
On Friday, June 29, 2012 10:00:49 PM UTC-7, Michael Hunger wrote:
> Usually you should be able to do:
> start node = ... > where {value} in node.array > set node.array = node.array + {value}
> Please try this
> Michael
> Am 30.06.2012 um 03:02 schrieb Mat Tyndall:
> So turns out adding to an array is easy, "SET node.array = node.array + > value", however I can't figure out how to conditionally create the array > property if it doesn't exist without splitting this into 2 queries.
> On Friday, June 29, 2012 3:55:49 PM UTC-7, Mat Tyndall wrote:
>> So I'm trying to check to see if a value exists in an array on a node and >> then if it doesn't add it.
>> Example: check if 'c' is present in (node {array:['a','b']}) and if not >> add it (node {array:['a','b','c']}).
>> I get the feeling with the various functions that I can iterate through >> the array and use regular expressions to test each value but how do I then >> push a new value into the array?
>> I'm pretty sure I could split it into 2 queries but one would be better.
>> I'm going to experiment in the console but if anybody has already solved >> this problem I'd love to see.
On Sat, Jun 30, 2012 at 3:16 PM, Mat Tyndall <mat.tynd...@gmail.com> wrote:
> that works, but if the array property hasn't been created yet it throws an
> error.
> On Friday, June 29, 2012 10:00:49 PM UTC-7, Michael Hunger wrote:
>> Usually you should be able to do:
>> start node = ...
>> where {value} in node.array
>> set node.array = node.array + {value}
>> Please try this
>> Michael
>> Am 30.06.2012 um 03:02 schrieb Mat Tyndall:
>> So turns out adding to an array is easy, "SET node.array = node.array +
>> value", however I can't figure out how to conditionally create the array
>> property if it doesn't exist without splitting this into 2 queries.
>> On Friday, June 29, 2012 3:55:49 PM UTC-7, Mat Tyndall wrote:
>>> So I'm trying to check to see if a value exists in an array on a node
>>> and then if it doesn't add it.
>>> Example: check if 'c' is present in (node {array:['a','b']}) and if not
>>> add it (node {array:['a','b','c']}).
>>> I get the feeling with the various functions that I can iterate through
>>> the array and use regular expressions to test each value but how do I then
>>> push a new value into the array?
>>> I'm pretty sure I could split it into 2 queries but one would be better.
>>> I'm going to experiment in the console but if anybody has already solved
>>> this problem I'd love to see.
> First time posting on the list, but I've been doing some similar stuff.
> You can deal with the not-yet-created problem with coalesce, eg
> start node = ...
> set node.array = coalesce(node.array?, []) + value
> (Just tried it out on a reasonably recent milestone).
> I hope that helps,
> Russell
> On Sat, Jun 30, 2012 at 3:16 PM, Mat Tyndall <mat.tynd...@gmail.com> wrote:
> that works, but if the array property hasn't been created yet it throws an error.
> On Friday, June 29, 2012 10:00:49 PM UTC-7, Michael Hunger wrote:
> Usually you should be able to do:
> start node = ...
> where {value} in node.array
> set node.array = node.array + {value}
> Please try this
> Michael
> Am 30.06.2012 um 03:02 schrieb Mat Tyndall:
>> So turns out adding to an array is easy, "SET node.array = node.array + value", however I can't figure out how to conditionally create the array property if it doesn't exist without splitting this into 2 queries.
>> On Friday, June 29, 2012 3:55:49 PM UTC-7, Mat Tyndall wrote:
>> So I'm trying to check to see if a value exists in an array on a node and then if it doesn't add it.
>> Example: check if 'c' is present in (node {array:['a','b']}) and if not add it (node {array:['a','b','c']}).
>> I get the feeling with the various functions that I can iterate through the array and use regular expressions to test each value but how do I then push a new value into the array?
>> I'm pretty sure I could split it into 2 queries but one would be better.
>> I'm going to experiment in the console but if anybody has already solved this problem I'd love to see.
On Sunday, July 1, 2012 12:13:19 AM UTC-7, Michael Hunger wrote:
> Thanks Russell, that's correct, I think we should add an example for this > whole use-case to the manual.
> Michael
> Am 01.07.2012 um 01:46 schrieb Russell Duhon:
> Hi,
> First time posting on the list, but I've been doing some similar stuff.
> You can deal with the not-yet-created problem with coalesce, eg
> start node = ... > set node.array = coalesce(node.array?, []) + value
> (Just tried it out on a reasonably recent milestone).
> I hope that helps, > Russell
> On Sat, Jun 30, 2012 at 3:16 PM, Mat Tyndall wrote:
>> that works, but if the array property hasn't been created yet it throws >> an error.
>> On Friday, June 29, 2012 10:00:49 PM UTC-7, Michael Hunger wrote:
>>> Usually you should be able to do:
>>> start node = ... >>> where {value} in node.array >>> set node.array = node.array + {value}
>>> Please try this
>>> Michael
>>> Am 30.06.2012 um 03:02 schrieb Mat Tyndall:
>>> So turns out adding to an array is easy, "SET node.array = node.array + >>> value", however I can't figure out how to conditionally create the array >>> property if it doesn't exist without splitting this into 2 queries.
>>> On Friday, June 29, 2012 3:55:49 PM UTC-7, Mat Tyndall wrote:
>>>> So I'm trying to check to see if a value exists in an array on a node >>>> and then if it doesn't add it.
>>>> Example: check if 'c' is present in (node {array:['a','b']}) and if not >>>> add it (node {array:['a','b','c']}).
>>>> I get the feeling with the various functions that I can iterate through >>>> the array and use regular expressions to test each value but how do I then >>>> push a new value into the array?
>>>> I'm pretty sure I could split it into 2 queries but one would be better.
>>>> I'm going to experiment in the console but if anybody has already >>>> solved this problem I'd love to see.