Mgconsole non-interactive mode to run queries

:bug: Bug Report

Description

We would to create user, run query through mgconsole non-interactively

Steps to reproduce

mgconsole “show users ;” so we can see the users
(Write your steps here:)

Step 1: mgconsole
Step 2: show users
Step 3 and 2 works , how can i send this in one single command (mgconsole in non-interactive mode)

Expected behavior

I can do this
cat test.txt
show users ;
root@90bdd537ae1a:/usr/lib/memgraph# mgconsole --username=username --password=password < test.txt
±---------+
| user |
±---------+
| “user” |
±---------+

(Write what you thought would happen.)

Actual behavior

(Write what happened. Add full console log messages and screenshots, if applicable.)

Your environment

  • Memgraph version used
  • Operating system and version (e.g., Ubuntu 20.04.2 LTS)

Hi @sgupops, you should be able to do this. We maybe didn’t document that properly.

For the setup, I have executed:

CREATE USER foo;
SET PASSWORD FOR foo to "bar";
SHOW USERS;

My test.txt file has the following command:
SHOW USERS;

Running this:
mgconsole --username=foo --password=bar < test.txt

Output:

Not sure what issue you are getting, can you add more details on what did you get on output?

Yes this works fine, but I am looking to pass as an argument in mgconsole, So i can avoid creating files for simple commands.

Ok @sgupops , I understand now, this is currently not supported. I have open the issue for this. You can track the progress here: Enable to execute single query without entering into interactive mode · Issue #48 · memgraph/mgconsole · GitHub :slightly_smiling_face:

It’s also possible to do the following:

echo "MATCH (n) RETURN n;" | mgconsole
# or
cat file.cypherl | mgconsole --username=foo --password=bar

A ok pipes work, we should probably document this a bit better.

1 Like