Message from discussion
cypher query to connect a where clause with the elements of an array
Date: Thu, 8 Nov 2012 09:25:25 -0800 (PST)
From: divyanshu das <divyanshu....@gmail.com>
To: neo4j@googlegroups.com
Message-Id: <a8d34a47-057b-4b5e-ae3b-e0eb1db27ae4@googlegroups.com>
In-Reply-To: <CAAOkgHN9e47K9TxrpXEjtjFbv5hG0jnsdBJB5gtYoWGw+z7GEQ@mail.gmail.com>
References: <7b4f7d5e-7f1d-4a7d-a93f-9e840a88aa86@googlegroups.com>
<CAAOkgHMLHXePFADo7RQQFdugXEHeuaNeXyo=Gf69jCs0ROEq0g@mail.gmail.com>
<CAAOkgHPW0TXdtNwvYwp7G7vSeaATbVDseaukrZtWKnyN3+NUyw@mail.gmail.com>
<f8a6dacf-a1f5-4eda-bf1c-dc24e1a00502@googlegroups.com> <be1f9e15-8c04-4a42-a419-9063cfb5046a@googlegroups.com>
<CAAOkgHN0w_ZLfch6=nFyYUxHBYtnNtDrM1jrMLyne8fe9AKF9Q@mail.gmail.com>
<baa21a00-9ed5-43ad-a995-6108992d8f30@googlegroups.com> <CAAOkgHOWUg6sGbQrsCRmEYu8kyHmoVkqc=_BeTZAw14mNoAAsQ@mail.gmail.com>
<155260dc-344c-4ab2-ab1d-c679a1605124@googlegroups.com>
<CAAOkgHN9e47K9TxrpXEjtjFbv5hG0jnsdBJB5gtYoWGw+z7GEQ@mail.gmail.com>
Subject: Re: [Neo4j] cypher query to connect a where clause with the
elements of an array
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_111_7507902.1352395525534"
------=_Part_111_7507902.1352395525534
Content-Type: multipart/alternative;
boundary="----=_Part_112_20645965.1352395525534"
------=_Part_112_20645965.1352395525534
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
I am using cypher queries as mentioned in
https://github.com/jadell/neo4jphp/wiki/Cypher-and-gremlin-queries
my phparray is $result_array, so will the query look like this?
$queryTemplate = "START n = node(*) MATCH n-[:rel]->() WHERE not(n.prop in
{phparr}) Return n", params:{phparra:$result_array};
On Thursday, 8 November 2012 22:47:42 UTC+5:30, Wes Freeman wrote:
>
> You can also specify a literal array in cypher... not sure what you're
> using from PHP, but you can do something like this via REST:
> {query:"start n=node(*)
> match n-[:rel]->()
> where not(n.prop in {phparr})
> return n;", params:{phparr:[1,2,3]}}
>
> On Thu, Nov 8, 2012 at 11:55 AM, divyanshu das <divyan...@gmail.com<javascript:>
> > wrote:
>
>> @Freeman, The code that you gave works for array when it is in neo4j.
>>
>> I have a separate php array that I am fetching from mysql.
>>
>> I need to delete the nodes and relationships for nodes whose certain
>> property matches the values stored in thee array.
>>
>>
>> On Thursday, 8 November 2012 03:23:19 UTC+5:30, Wes Freeman wrote:
>>
>>> Well, I think the REST delete commands existed in 1.6 if you're using
>>> server. If you're using embedded, you can do it like this:
>>> http://docs.neo4j.org/chunked/**stable/tutorials-java-**
>>> embedded-hello-world.html#_**remove_the_data<http://docs.neo4j.org/chunked/stable/tutorials-java-embedded-hello-world.html#_remove_the_data>
>>>
>>> On Wed, Nov 7, 2012 at 4:36 PM, divyanshu das <divyan...@gmail.com>wrote:
>>>
>>>> Is there any other way to delete nodes in 1.6.1 without using cypher
>>>> queries?
>>>>
>>>>
>>>> On Thursday, 8 November 2012 02:56:56 UTC+5:30, Wes Freeman wrote:
>>>>
>>>>> It isn't a good idea to depend on node ids for long term use (rather,
>>>>> use an email address or guid or similar unique id, with an index). Ids are
>>>>> reused after you restart the server, I think, if they were deleted.
>>>>>
>>>>> Wes
>>>>>
>>>>>
>>>>> On Wed, Nov 7, 2012 at 4:18 PM, divyanshu das <divyan...@gmail.com>wrote:
>>>>>
>>>>>> If I upgrade to 1.8, then I get the delete queries. Now, If I delete
>>>>>> the nodes, will the node ids for other users remain unchanged or neo4j
>>>>>> automatically reuses the deleted ids?
>>>>>>
>>>>>>
>>>>>> On Thursday, 8 November 2012 02:42:51 UTC+5:30, divyanshu das wrote:
>>>>>>>
>>>>>>> Hey, thanks for prompt replies. If I am correct, node(*) method is
>>>>>>> not available in 1.6.1. Any workaround for this?
>>>>>>>
>>>>>>> On Thursday, 8 November 2012 02:40:29 UTC+5:30, Wes Freeman wrote:
>>>>>>>>
>>>>>>>> I guess that's not exactly what you asked for... how about this:
>>>>>>>>
>>>>>>>> http://console.neo4j.org/r/**xg5****y9u<http://console.neo4j.org/r/xg5y9u>
>>>>>>>>
>>>>>>>> start n=node(*)
>>>>>>>> match n-[:rel]->()
>>>>>>>> where has(n.arr) and not(n.prop in n.arr)
>>>>>>>> return n;
>>>>>>>>
>>>>>>>> On Wed, Nov 7, 2012 at 3:54 PM, Wes Freeman <freem...@gmail.com>wrote:
>>>>>>>>
>>>>>>>>> You can't delete via Cypher with that version of Neo.
>>>>>>>>>
>>>>>>>>> If you want to just find them, you could do something like (I'm
>>>>>>>>> not entirely sure this worked back then, either--you might consider
>>>>>>>>> upgrading):
>>>>>>>>>
>>>>>>>>> start n=node(*)
>>>>>>>>> where n.prop in n.arr
>>>>>>>>> return n;
>>>>>>>>>
>>>>>>>>> Wes
>>>>>>>>>
>>>>>>>>> On Wed, Nov 7, 2012 at 3:43 PM, divyanshu das <divyan...@gmail.com
>>>>>>>>> > wrote:
>>>>>>>>>
>>>>>>>>>> I have neo4j 1.6.1 and I am using php .
>>>>>>>>>>
>>>>>>>>>> I have an array "arr" of a particular property "prop" of nodes.
>>>>>>>>>>
>>>>>>>>>> I want to delete all nodes from neo4j having a certain
>>>>>>>>>> relationship "rel" except for the nodes whose property "prop" is in the
>>>>>>>>>> array "arr".
>>>>>>>>>>
>>>>>>>>>> Can somebody help me out with this?
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>> --
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> --
>>>>
>>>>
>>>>
>>>
>>> --
>>
>>
>>
>
>
------=_Part_112_20645965.1352395525534
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
I am using cypher queries as mentioned in <a href="https://github.com/jadell/neo4jphp/wiki/Cypher-and-gremlin-queries">https://github.com/jadell/neo4jphp/wiki/Cypher-and-gremlin-queries</a><div><br></div><div>my phparray is $result_array, so will the query look like this?</div><div><br></div><div>$queryTemplate = "START n = node(*) MATCH n-[:rel]->() WHERE not(n.prop in {phparr}) Return n", params:{phparra:$result_array};</div><div><br><br>On Thursday, 8 November 2012 22:47:42 UTC+5:30, Wes Freeman wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">You can also specify a literal array in cypher... not sure what you're using from PHP, but you can do something like this via REST:<div>{query:"<span style="color:rgb(80,0,80)">start n=node(*) </span><div style="color:rgb(80,0,80)">
match n-[:rel]->() </div><div style="color:rgb(80,0,80)">where not(n.prop in {phparr}) </div><div style="color:rgb(80,0,80)">return n;", params:{phparr:[1,2,3]}}</div><div><br><div class="gmail_quote">
On Thu, Nov 8, 2012 at 11:55 AM, divyanshu das <span dir="ltr"><<a href="javascript:" target="_blank" gdf-obfuscated-mailto="-4zCN1H1m_IJ">divyan...@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
@Freeman, The code that you gave works for array when it is in neo4j.<div><br></div><div>I have a separate php array that I am fetching from mysql.</div><div><br></div><div>I need to delete the nodes and relationships for nodes whose certain property matches the values stored in thee array.<div>
<br><br>On Thursday, 8 November 2012 03:23:19 UTC+5:30, Wes Freeman wrote:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div>Well, I think the REST delete commands existed in 1.6 if you're using server. If you're using embedded, you can do it like this:<br><a href="http://docs.neo4j.org/chunked/stable/tutorials-java-embedded-hello-world.html#_remove_the_data" target="_blank">http://docs.neo4j.org/chunked/<u></u><wbr>stable/tutorials-java-<u></u>embedded<wbr>-hello-world.html#_<u></u>remove_the_<wbr>data</a><br>
</div><br></div><div><div><div><div class="gmail_quote">On Wed, Nov 7, 2012 at 4:36 PM, divyanshu das <span dir="ltr"><<a>divyan...@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Is there any other way to delete nodes in 1.6.1 without using cypher queries?<div>
<br><br>On Thursday, 8 November 2012 02:56:56 UTC+5:30, Wes Freeman wrote:</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>It isn't a good idea to depend on node ids for long term use (rather, use an email address or guid or similar unique id, with an index). Ids are reused after you restart the server, I think, if they were deleted.<div>
<br>
</div></div><div>Wes<div><div><br><div><br><div class="gmail_quote">On Wed, Nov 7, 2012 at 4:18 PM, divyanshu das <span dir="ltr"><<a>divyan...@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">If I upgrade to 1.8, then I get the delete queries. Now, If I delete the nodes, will the node ids for other users remain unchanged or neo4j automatically reuses the deleted ids?<div>
<div><br><br>On Thursday, 8 November 2012 02:42:51 UTC+5:30, divyanshu das wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Hey, thanks for prompt replies. If I am correct, node(*) method is not available in 1.6.1. Any workaround for this?<br>
<br>On Thursday, 8 November 2012 02:40:29 UTC+5:30, Wes Freeman wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div>I guess that's not exactly what you asked for... how about this:<br>
<br></div><div><a href="http://console.neo4j.org/r/xg5y9u" target="_blank">http://console.neo4j.org/r/<u></u>xg5<u></u><u></u><wbr>y9u</a><br></div><div><br></div><div><div>start n=node(*) </div>
<div>match n-[:rel]->() </div><div>where has(n.arr) and not(n.prop in n.arr) </div><div>return n;</div></div><br><div><div class="gmail_quote">On Wed, Nov 7, 2012 at 3:54 PM, Wes Freeman <span dir="ltr"><<a>freem...@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">You can't delete via Cypher with that version of Neo. <div>
<br></div><div>If you want to just find them, you could do something like (I'm not entirely sure this worked back then, either--you might consider upgrading):</div>
<div><br>start n=node(*)<br>where n.prop in n.arr<br>return n;<br><div><br></div><div>Wes</div><div><div><div><br><div class="gmail_quote">On Wed, Nov 7, 2012 at 3:43 PM, divyanshu das <span dir="ltr"><<a>divyan...@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>I have neo4j 1.6.1 and I am using php .</div><div><br>
</div>I have an array "arr" of a particular property "prop" of nodes.<div>
<br></div><div>I want to delete all nodes from neo4j having a certain relationship "rel" except for the nodes whose property "prop" is in the array "arr".</div><div><br></div><div>Can somebody help me out with this? </div>
<span><font color="#888888">
<p></p>
-- <br>
<br>
<br>
</font></span></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>
</blockquote></blockquote>
<p></p>
-- <br>
<br>
<br>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote>
<p></p>
-- <br>
<br>
<br>
</blockquote></div><br></div>
</div></div></blockquote></div>
<p></p>
-- <br>
<br>
<br>
</blockquote></div><br></div></div>
</blockquote></div>
------=_Part_112_20645965.1352395525534--
------=_Part_111_7507902.1352395525534--