Neo4j cypher query fails with unknown syntax error












0














I have the following paramObj and dbQuery



 paramObj = {
email: newUser.email,
mobilenumber: newUser.telephone,
password: newUser.password,
category: newUser.category,
name: newUser.name,
confirmuid: verificationHash,
confirmexpire: expiryDate.valueOf(),
rewardPoints: 0,
emailconfirmed: 'false',
paramVehicles: makeVehicleArray,
paramVehicleProps: vehiclePropsArray
}
dbQuery = `CREATE (user:Person:Owner {email:$email})
SET user += apoc.map.clean(paramObj,
['email','paramVehicles','paramVehiclesProps'],)
WITH user, $paramVehicles AS vehicles
UNWIND vehicles AS vehicle
MATCH(v:Vehicles {name:vehicle})
CREATE UNIQUE (user)-[r:OWNS {since: timestamp()}]->(v)
RETURN user,r,v`;


Then I tried to execute



 commons.session
.run(dbQuery, paramObj)
.then(newUser => {
commons.session.close();
if (!newUser.records[0]) {........


I am getting



Error:  {"code":"Neo.ClientError.Statement.SyntaxError","name":"Neo4jError"}


which doesn't direct me anywhere. Can anyone tell me what am I doing wrong here?



This is actually the first time I am using the query format .run(dbQuery, paramObj) but this format is critical to my use case. I am using Neo4j 3.4.5 community with apoc plugin installed.



Ok...so I followed @inversFalcon suggestion to test in browser and came up with following parameters and query that closely match the ones above:



   :params paramObj:[{ email:"xyz123@abc.com", mobilenumber:"8711231234",password:"password1", category:"Owner",name:"Michaell",vehicles:["Toyota","BMW","Nissan"],vehicleProps:  }]


and query



PROFILE
CREATE (user:Person:Owner {email:$email})
SET user += apoc.map.clean($paramObj, ["email","vehicles","vehicleProps"],)
WITH user, $vehicles AS vehicles
UNWIND vehicles AS vehicle
MATCH(v:Vehicles {name:vehicle})
MERGE (user)-[r:OWNS {since: timestamp()}]->(v)
RETURN user,r,v;


Now I get
Neo.ClientError.Statement.TypeError: Can't coerce `List{Map{name -> String("Michaell"), vehicles -> List{String("Toyota"), String("BMW"), String("Nissan")},.......



I also reverted to neo4j 3.2 (re: an earlier post by Mark Needham) and got the same error.










share|improve this question





























    0














    I have the following paramObj and dbQuery



     paramObj = {
    email: newUser.email,
    mobilenumber: newUser.telephone,
    password: newUser.password,
    category: newUser.category,
    name: newUser.name,
    confirmuid: verificationHash,
    confirmexpire: expiryDate.valueOf(),
    rewardPoints: 0,
    emailconfirmed: 'false',
    paramVehicles: makeVehicleArray,
    paramVehicleProps: vehiclePropsArray
    }
    dbQuery = `CREATE (user:Person:Owner {email:$email})
    SET user += apoc.map.clean(paramObj,
    ['email','paramVehicles','paramVehiclesProps'],)
    WITH user, $paramVehicles AS vehicles
    UNWIND vehicles AS vehicle
    MATCH(v:Vehicles {name:vehicle})
    CREATE UNIQUE (user)-[r:OWNS {since: timestamp()}]->(v)
    RETURN user,r,v`;


    Then I tried to execute



     commons.session
    .run(dbQuery, paramObj)
    .then(newUser => {
    commons.session.close();
    if (!newUser.records[0]) {........


    I am getting



    Error:  {"code":"Neo.ClientError.Statement.SyntaxError","name":"Neo4jError"}


    which doesn't direct me anywhere. Can anyone tell me what am I doing wrong here?



    This is actually the first time I am using the query format .run(dbQuery, paramObj) but this format is critical to my use case. I am using Neo4j 3.4.5 community with apoc plugin installed.



    Ok...so I followed @inversFalcon suggestion to test in browser and came up with following parameters and query that closely match the ones above:



       :params paramObj:[{ email:"xyz123@abc.com", mobilenumber:"8711231234",password:"password1", category:"Owner",name:"Michaell",vehicles:["Toyota","BMW","Nissan"],vehicleProps:  }]


    and query



    PROFILE
    CREATE (user:Person:Owner {email:$email})
    SET user += apoc.map.clean($paramObj, ["email","vehicles","vehicleProps"],)
    WITH user, $vehicles AS vehicles
    UNWIND vehicles AS vehicle
    MATCH(v:Vehicles {name:vehicle})
    MERGE (user)-[r:OWNS {since: timestamp()}]->(v)
    RETURN user,r,v;


    Now I get
    Neo.ClientError.Statement.TypeError: Can't coerce `List{Map{name -> String("Michaell"), vehicles -> List{String("Toyota"), String("BMW"), String("Nissan")},.......



    I also reverted to neo4j 3.2 (re: an earlier post by Mark Needham) and got the same error.










    share|improve this question



























      0












      0








      0







      I have the following paramObj and dbQuery



       paramObj = {
      email: newUser.email,
      mobilenumber: newUser.telephone,
      password: newUser.password,
      category: newUser.category,
      name: newUser.name,
      confirmuid: verificationHash,
      confirmexpire: expiryDate.valueOf(),
      rewardPoints: 0,
      emailconfirmed: 'false',
      paramVehicles: makeVehicleArray,
      paramVehicleProps: vehiclePropsArray
      }
      dbQuery = `CREATE (user:Person:Owner {email:$email})
      SET user += apoc.map.clean(paramObj,
      ['email','paramVehicles','paramVehiclesProps'],)
      WITH user, $paramVehicles AS vehicles
      UNWIND vehicles AS vehicle
      MATCH(v:Vehicles {name:vehicle})
      CREATE UNIQUE (user)-[r:OWNS {since: timestamp()}]->(v)
      RETURN user,r,v`;


      Then I tried to execute



       commons.session
      .run(dbQuery, paramObj)
      .then(newUser => {
      commons.session.close();
      if (!newUser.records[0]) {........


      I am getting



      Error:  {"code":"Neo.ClientError.Statement.SyntaxError","name":"Neo4jError"}


      which doesn't direct me anywhere. Can anyone tell me what am I doing wrong here?



      This is actually the first time I am using the query format .run(dbQuery, paramObj) but this format is critical to my use case. I am using Neo4j 3.4.5 community with apoc plugin installed.



      Ok...so I followed @inversFalcon suggestion to test in browser and came up with following parameters and query that closely match the ones above:



         :params paramObj:[{ email:"xyz123@abc.com", mobilenumber:"8711231234",password:"password1", category:"Owner",name:"Michaell",vehicles:["Toyota","BMW","Nissan"],vehicleProps:  }]


      and query



      PROFILE
      CREATE (user:Person:Owner {email:$email})
      SET user += apoc.map.clean($paramObj, ["email","vehicles","vehicleProps"],)
      WITH user, $vehicles AS vehicles
      UNWIND vehicles AS vehicle
      MATCH(v:Vehicles {name:vehicle})
      MERGE (user)-[r:OWNS {since: timestamp()}]->(v)
      RETURN user,r,v;


      Now I get
      Neo.ClientError.Statement.TypeError: Can't coerce `List{Map{name -> String("Michaell"), vehicles -> List{String("Toyota"), String("BMW"), String("Nissan")},.......



      I also reverted to neo4j 3.2 (re: an earlier post by Mark Needham) and got the same error.










      share|improve this question















      I have the following paramObj and dbQuery



       paramObj = {
      email: newUser.email,
      mobilenumber: newUser.telephone,
      password: newUser.password,
      category: newUser.category,
      name: newUser.name,
      confirmuid: verificationHash,
      confirmexpire: expiryDate.valueOf(),
      rewardPoints: 0,
      emailconfirmed: 'false',
      paramVehicles: makeVehicleArray,
      paramVehicleProps: vehiclePropsArray
      }
      dbQuery = `CREATE (user:Person:Owner {email:$email})
      SET user += apoc.map.clean(paramObj,
      ['email','paramVehicles','paramVehiclesProps'],)
      WITH user, $paramVehicles AS vehicles
      UNWIND vehicles AS vehicle
      MATCH(v:Vehicles {name:vehicle})
      CREATE UNIQUE (user)-[r:OWNS {since: timestamp()}]->(v)
      RETURN user,r,v`;


      Then I tried to execute



       commons.session
      .run(dbQuery, paramObj)
      .then(newUser => {
      commons.session.close();
      if (!newUser.records[0]) {........


      I am getting



      Error:  {"code":"Neo.ClientError.Statement.SyntaxError","name":"Neo4jError"}


      which doesn't direct me anywhere. Can anyone tell me what am I doing wrong here?



      This is actually the first time I am using the query format .run(dbQuery, paramObj) but this format is critical to my use case. I am using Neo4j 3.4.5 community with apoc plugin installed.



      Ok...so I followed @inversFalcon suggestion to test in browser and came up with following parameters and query that closely match the ones above:



         :params paramObj:[{ email:"xyz123@abc.com", mobilenumber:"8711231234",password:"password1", category:"Owner",name:"Michaell",vehicles:["Toyota","BMW","Nissan"],vehicleProps:  }]


      and query



      PROFILE
      CREATE (user:Person:Owner {email:$email})
      SET user += apoc.map.clean($paramObj, ["email","vehicles","vehicleProps"],)
      WITH user, $vehicles AS vehicles
      UNWIND vehicles AS vehicle
      MATCH(v:Vehicles {name:vehicle})
      MERGE (user)-[r:OWNS {since: timestamp()}]->(v)
      RETURN user,r,v;


      Now I get
      Neo.ClientError.Statement.TypeError: Can't coerce `List{Map{name -> String("Michaell"), vehicles -> List{String("Toyota"), String("BMW"), String("Nissan")},.......



      I also reverted to neo4j 3.2 (re: an earlier post by Mark Needham) and got the same error.







      neo4j cypher






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 at 17:21

























      asked Nov 23 at 0:50









      MichaelE

      233113




      233113
























          2 Answers
          2






          active

          oldest

          votes


















          2














          You should try doing an EXPLAIN of the query using the browser to troubleshoot it.



          A few of the things I'm seeing here:



          You're referring to paramObj, but it's not a parameter (rather, it's the map of parameters you're passing in, but it itself is not a parameter you can reference in the query). If you need to reference the entire set of parameters being passed in, then you need to use nested maps, and have paramObj be a key in the map that you pass as the parameter map (and when you do use it in the query, you'll need to use $paramObj)



          CREATE UNIQUE is deprecated, you should use MERGE instead, though be aware that it does behave in a different manner (see the MERGE documentation as well as our knowledge base article explaining some of the easy-to-miss details of how MERGE works).






          share|improve this answer





















          • I have edited the question with some of your suggestions now I think we making progress.... but I am now getting coercion errors.
            – MichaelE
            Nov 23 at 17:24










          • Also, will apoc.map.clean() or apoc.map.removeKeys() mutate the paramObj making it unusable further on in the query?
            – MichaelE
            Nov 23 at 18:06










          • They aren't mutators, they should return a separate map with the changes applied, the original should still be usable
            – InverseFalcon
            Nov 24 at 18:32










          • With the change you applied, paramObj now refers to a list, not a map, see those square brackets? Get rid of those
            – InverseFalcon
            Nov 24 at 18:34



















          0














          I am not sure what caused the coercion error to disappear but it did with the same query and I got a "expected parameter error" this was fixed by using $paramObj.email, etc. so the final query looks like this:



          CREATE (user:Person:Owner {email: $paramObj.email})
          SET user += apoc.map.clean($queryObj, ["email","vehicles","vehicleProps"],)
          WITH user, $paramObj.vehicles AS vehicles
          UNWIND vehicles AS vehicle
          MATCH(v:Vehicles {name:vehicle})
          MERGE (user)-[r:OWNS {since: timestamp()}]->(v)
          RETURN user,r,v;


          which fixed my original problem of how to remove properties from a map when using SET += map.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439491%2fneo4j-cypher-query-fails-with-unknown-syntax-error%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You should try doing an EXPLAIN of the query using the browser to troubleshoot it.



            A few of the things I'm seeing here:



            You're referring to paramObj, but it's not a parameter (rather, it's the map of parameters you're passing in, but it itself is not a parameter you can reference in the query). If you need to reference the entire set of parameters being passed in, then you need to use nested maps, and have paramObj be a key in the map that you pass as the parameter map (and when you do use it in the query, you'll need to use $paramObj)



            CREATE UNIQUE is deprecated, you should use MERGE instead, though be aware that it does behave in a different manner (see the MERGE documentation as well as our knowledge base article explaining some of the easy-to-miss details of how MERGE works).






            share|improve this answer





















            • I have edited the question with some of your suggestions now I think we making progress.... but I am now getting coercion errors.
              – MichaelE
              Nov 23 at 17:24










            • Also, will apoc.map.clean() or apoc.map.removeKeys() mutate the paramObj making it unusable further on in the query?
              – MichaelE
              Nov 23 at 18:06










            • They aren't mutators, they should return a separate map with the changes applied, the original should still be usable
              – InverseFalcon
              Nov 24 at 18:32










            • With the change you applied, paramObj now refers to a list, not a map, see those square brackets? Get rid of those
              – InverseFalcon
              Nov 24 at 18:34
















            2














            You should try doing an EXPLAIN of the query using the browser to troubleshoot it.



            A few of the things I'm seeing here:



            You're referring to paramObj, but it's not a parameter (rather, it's the map of parameters you're passing in, but it itself is not a parameter you can reference in the query). If you need to reference the entire set of parameters being passed in, then you need to use nested maps, and have paramObj be a key in the map that you pass as the parameter map (and when you do use it in the query, you'll need to use $paramObj)



            CREATE UNIQUE is deprecated, you should use MERGE instead, though be aware that it does behave in a different manner (see the MERGE documentation as well as our knowledge base article explaining some of the easy-to-miss details of how MERGE works).






            share|improve this answer





















            • I have edited the question with some of your suggestions now I think we making progress.... but I am now getting coercion errors.
              – MichaelE
              Nov 23 at 17:24










            • Also, will apoc.map.clean() or apoc.map.removeKeys() mutate the paramObj making it unusable further on in the query?
              – MichaelE
              Nov 23 at 18:06










            • They aren't mutators, they should return a separate map with the changes applied, the original should still be usable
              – InverseFalcon
              Nov 24 at 18:32










            • With the change you applied, paramObj now refers to a list, not a map, see those square brackets? Get rid of those
              – InverseFalcon
              Nov 24 at 18:34














            2












            2








            2






            You should try doing an EXPLAIN of the query using the browser to troubleshoot it.



            A few of the things I'm seeing here:



            You're referring to paramObj, but it's not a parameter (rather, it's the map of parameters you're passing in, but it itself is not a parameter you can reference in the query). If you need to reference the entire set of parameters being passed in, then you need to use nested maps, and have paramObj be a key in the map that you pass as the parameter map (and when you do use it in the query, you'll need to use $paramObj)



            CREATE UNIQUE is deprecated, you should use MERGE instead, though be aware that it does behave in a different manner (see the MERGE documentation as well as our knowledge base article explaining some of the easy-to-miss details of how MERGE works).






            share|improve this answer












            You should try doing an EXPLAIN of the query using the browser to troubleshoot it.



            A few of the things I'm seeing here:



            You're referring to paramObj, but it's not a parameter (rather, it's the map of parameters you're passing in, but it itself is not a parameter you can reference in the query). If you need to reference the entire set of parameters being passed in, then you need to use nested maps, and have paramObj be a key in the map that you pass as the parameter map (and when you do use it in the query, you'll need to use $paramObj)



            CREATE UNIQUE is deprecated, you should use MERGE instead, though be aware that it does behave in a different manner (see the MERGE documentation as well as our knowledge base article explaining some of the easy-to-miss details of how MERGE works).







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 at 1:34









            InverseFalcon

            18.2k21829




            18.2k21829












            • I have edited the question with some of your suggestions now I think we making progress.... but I am now getting coercion errors.
              – MichaelE
              Nov 23 at 17:24










            • Also, will apoc.map.clean() or apoc.map.removeKeys() mutate the paramObj making it unusable further on in the query?
              – MichaelE
              Nov 23 at 18:06










            • They aren't mutators, they should return a separate map with the changes applied, the original should still be usable
              – InverseFalcon
              Nov 24 at 18:32










            • With the change you applied, paramObj now refers to a list, not a map, see those square brackets? Get rid of those
              – InverseFalcon
              Nov 24 at 18:34


















            • I have edited the question with some of your suggestions now I think we making progress.... but I am now getting coercion errors.
              – MichaelE
              Nov 23 at 17:24










            • Also, will apoc.map.clean() or apoc.map.removeKeys() mutate the paramObj making it unusable further on in the query?
              – MichaelE
              Nov 23 at 18:06










            • They aren't mutators, they should return a separate map with the changes applied, the original should still be usable
              – InverseFalcon
              Nov 24 at 18:32










            • With the change you applied, paramObj now refers to a list, not a map, see those square brackets? Get rid of those
              – InverseFalcon
              Nov 24 at 18:34
















            I have edited the question with some of your suggestions now I think we making progress.... but I am now getting coercion errors.
            – MichaelE
            Nov 23 at 17:24




            I have edited the question with some of your suggestions now I think we making progress.... but I am now getting coercion errors.
            – MichaelE
            Nov 23 at 17:24












            Also, will apoc.map.clean() or apoc.map.removeKeys() mutate the paramObj making it unusable further on in the query?
            – MichaelE
            Nov 23 at 18:06




            Also, will apoc.map.clean() or apoc.map.removeKeys() mutate the paramObj making it unusable further on in the query?
            – MichaelE
            Nov 23 at 18:06












            They aren't mutators, they should return a separate map with the changes applied, the original should still be usable
            – InverseFalcon
            Nov 24 at 18:32




            They aren't mutators, they should return a separate map with the changes applied, the original should still be usable
            – InverseFalcon
            Nov 24 at 18:32












            With the change you applied, paramObj now refers to a list, not a map, see those square brackets? Get rid of those
            – InverseFalcon
            Nov 24 at 18:34




            With the change you applied, paramObj now refers to a list, not a map, see those square brackets? Get rid of those
            – InverseFalcon
            Nov 24 at 18:34













            0














            I am not sure what caused the coercion error to disappear but it did with the same query and I got a "expected parameter error" this was fixed by using $paramObj.email, etc. so the final query looks like this:



            CREATE (user:Person:Owner {email: $paramObj.email})
            SET user += apoc.map.clean($queryObj, ["email","vehicles","vehicleProps"],)
            WITH user, $paramObj.vehicles AS vehicles
            UNWIND vehicles AS vehicle
            MATCH(v:Vehicles {name:vehicle})
            MERGE (user)-[r:OWNS {since: timestamp()}]->(v)
            RETURN user,r,v;


            which fixed my original problem of how to remove properties from a map when using SET += map.






            share|improve this answer


























              0














              I am not sure what caused the coercion error to disappear but it did with the same query and I got a "expected parameter error" this was fixed by using $paramObj.email, etc. so the final query looks like this:



              CREATE (user:Person:Owner {email: $paramObj.email})
              SET user += apoc.map.clean($queryObj, ["email","vehicles","vehicleProps"],)
              WITH user, $paramObj.vehicles AS vehicles
              UNWIND vehicles AS vehicle
              MATCH(v:Vehicles {name:vehicle})
              MERGE (user)-[r:OWNS {since: timestamp()}]->(v)
              RETURN user,r,v;


              which fixed my original problem of how to remove properties from a map when using SET += map.






              share|improve this answer
























                0












                0








                0






                I am not sure what caused the coercion error to disappear but it did with the same query and I got a "expected parameter error" this was fixed by using $paramObj.email, etc. so the final query looks like this:



                CREATE (user:Person:Owner {email: $paramObj.email})
                SET user += apoc.map.clean($queryObj, ["email","vehicles","vehicleProps"],)
                WITH user, $paramObj.vehicles AS vehicles
                UNWIND vehicles AS vehicle
                MATCH(v:Vehicles {name:vehicle})
                MERGE (user)-[r:OWNS {since: timestamp()}]->(v)
                RETURN user,r,v;


                which fixed my original problem of how to remove properties from a map when using SET += map.






                share|improve this answer












                I am not sure what caused the coercion error to disappear but it did with the same query and I got a "expected parameter error" this was fixed by using $paramObj.email, etc. so the final query looks like this:



                CREATE (user:Person:Owner {email: $paramObj.email})
                SET user += apoc.map.clean($queryObj, ["email","vehicles","vehicleProps"],)
                WITH user, $paramObj.vehicles AS vehicles
                UNWIND vehicles AS vehicle
                MATCH(v:Vehicles {name:vehicle})
                MERGE (user)-[r:OWNS {since: timestamp()}]->(v)
                RETURN user,r,v;


                which fixed my original problem of how to remove properties from a map when using SET += map.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 at 21:24









                MichaelE

                233113




                233113






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439491%2fneo4j-cypher-query-fails-with-unknown-syntax-error%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)