3

I want to run more than one query .. how to do it?

eg, I have below two queries -

FOR doc IN users
    RETURN doc

FOR doc IN users
    RETURN { user: doc, newAttribute: true }

If I have to run both queries I have to run them separately, is there a way to execute a script or I need to put a semicolon at the end like SQL and run it.

Can I use arangosh?

1 Answer 1

4

You can use LET to execute multiple sub-queries in a single queries:

LET firstUserResult = (
   FOR doc IN users
   RETURN doc 
)

LET secondUserResult = (
   FOR doc IN users
   RETURN { user: doc, newAttribute: true }
)

RETURN { first: firstUserResult, second: secondUserResult }

Some notes here - you will need to add an additional RETURN statement at the end of the query. This will definitely work for reads but you may run into issues when trying to write in multiple queries.

Sign up to request clarification or add additional context in comments.

1 Comment

How can I combine them in javascript drivers ? For me, the number of queries get dynamic: I have a list of objs which needs to be stored in db. I need to check if any obj in the same collect exists with the same id, then delete the existing and insert the new. query1 = delete if the document with same id exists query2 = insert the new document both the queries I need to run for each items of the list that I have received from the user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.