Connect and run your first query¶
Connect to NebulaGraph Database Developer Edition with NebulaGraph Studio, load the movie sample dataset, and find a movie and its actors. Complete the four steps below in your browser.
Before you start¶
- Follow Deploy Developer Edition with Docker Compose to start NebulaGraph Database Developer Edition and the supplied NebulaGraph Studio.
- Have your current
rootpassword ready.
1. Sign in to NebulaGraph Studio¶
On the development machine running Docker, open http://127.0.0.1:7001 in your browser.
Access from another computer or use a custom port
Your browser reaches NebulaGraph Studio on port 7001; NebulaGraph Studio connects to NebulaGraph Database Developer Edition at graph-cluster:9669.
From another computer, open http://<development-machine-ip>:7001. Replace <development-machine-ip> with the IP address of the machine running Docker.
If you changed the 7001:7001 port mapping in compose.yaml, use the development machine port to the left of the colon in the browser address.
Confirm or enter these values on the login page, then select Connect:
| Field | Value |
|---|---|
| Address | graph-cluster |
| Port | 9669 |
| Username | root |
| Password | Your current root password. The initial password in the supplied file is NebulaGraph01; if you have changed it, enter the new password. |
After signing in, you can see SCHEMA and CONSOLE in the top navigation bar.
2. Load the movie sample dataset¶
A Schema groups graph types and graphs, much like a folder. This page uses the default Schema /default_schema, which the system creates automatically.
- Select the SCHEMA tab in the top navigation bar.
- Check that
default_schemais selected at the top of the left sidebar. - Select Use Demo Dataset in the center of the page.
- Wait for loading to finish. On success, the
movie_typegraph type details page opens.
Loading creates graph type movie_type and graph movie, then inserts movies, actors, and their relationships. movie_type defines the data structure; the queries below use graph movie.
After loading succeeds, Use Demo Dataset is no longer shown. On subsequent visits, continue with step 3 without reloading the dataset.
3. Find a movie¶
Select CONSOLE in the top navigation bar. Paste this query into the query editor and select the run button to find the movie with ID 3:
USE movie MATCH (m@Movie {id: 3}) RETURN m.id AS movie_id, m.name AS movie
Expected result:
| movie_id | movie |
|---|---|
| 3 | "Shadows in Paradise" |
The query uses these elements:
USE moviespecifies the graph for this query.MATCHfinds matching nodes.@Moviespecifies the movie type, and{id: 3}specifies the movie ID. An ID distinguishes movies with the same name.RETURNselects properties to display;ASnames the result columns.
movie is the graph name; Movie is a node type. Names are case-sensitive.
Set a working graph for the session
The queries on this page specify the graph with USE movie, which applies only to the query that contains it. You can instead set a working graph for the session:
SESSION SET GRAPH movie
Then omit USE movie from the start of the query:
MATCH (m@Movie {id: 3}) RETURN m.id AS movie_id, m.name AS movie
Set the working graph again after reconnecting. See USE for details.
4. Find the movie's actors¶
In the same console, replace the movie query with the following statement and run it to find the movie's actors:
USE movie MATCH (a@Actor)-[:Act]->(m@Movie {id: 3})
RETURN a.id AS actor_id, a.name AS actor, m.name AS movie
ORDER BY actor_id
Expected result:
| actor_id | actor | movie |
|---|---|---|
| 4826 | "Matti Pellonpää" | "Shadows in Paradise" |
| 4828 | "Sakari Kuosmanen" | "Shadows in Paradise" |
| 5999 | "Kati Outinen" | "Shadows in Paradise" |
(a@Actor)-[:Act]->(m@Movie) matches an actor's relationship to a movie they act in. The arrow points from actor to movie. ORDER BY actor_id sorts by actor ID.
Exit and resume your work
In NebulaGraph Studio, select Logout from the user menu in the upper right corner. In ngql, run :exit. After you exit the client, NebulaGraph Database Developer Edition continues running and retains its data. To stop the services, see Stop and restart the services.
Next time, sign in to NebulaGraph Studio and continue from step 3 to run the queries. You do not need to reload movie.
Other connection methods¶
These clients access the same NebulaGraph Database Developer Edition instance. After loading the data once, you can query it with any client.
Connect and load sample data with ngql
-
In the development machine's terminal, open the directory containing
compose.yamland run:docker compose exec ngql ngql --host graph-cluster --port 9669 --user rootThe first
ngqlis the Compose service name; the second is the client command inside the container. Keepgraph-cluster:9669, the query address on the container network. -
At the
Passwordprompt, enter the currentrootpassword and press Enter. -
If
moviehas not been loaded in/default_schema, run this command. Skip this step if loading has already succeeded.:play movieThe client displays
Playing dataset: movie...at the start andPlay dataset: movie done.on success. If loading fails, inspect the created objects and errors as described in Data loading.
Then run the examples from Find a movie and Find the movie's actors in the ngql interactive console.
For a multiline query, place ''' on its own line before and after the statement. Enter the closing line and press Enter to submit:
'''
USE movie MATCH (a@Actor)-[:Act]->(m@Movie {id: 3})
RETURN a.id AS actor_id, a.name AS actor, m.name AS movie
ORDER BY actor_id
'''
:play movie is an ngql client command. It cannot run in the query editors in NebulaGraph Studio or the built-in web console.
Connect with the built-in web console
NebulaGraph Database Console is a query interface built into the Graph service. It has a separate address from NebulaGraph Studio:
| Browser location | Address |
|---|---|
| On the same development machine as Docker | http://127.0.0.1:19669/ui/console |
| On another computer | http://<development-machine-ip>:19669/ui/console |
Replace <development-machine-ip> with the IP address of the machine running Docker. The supplied configuration uses HTTP. If you changed the 19669:19669 mapping, use the development machine port to the left of the colon.
Enter username root and the account's current password, then select Connect. Run the statements from step 3 and step 4 one at a time in the editor, selecting the run button for each. Paste multiline statements directly.
If the data is not loaded yet, load it through NebulaGraph Studio or ngql first, then return here to query it.
Troubleshooting¶
Check Studio access and sign-in
- The page does not open: Check the service status, ports, and logs in Studio page does not open.
- The page opens, but sign-in fails: Check the address, port, username, and actual password against step 1. To change an existing instance's password, follow Change an existing instance's root password.
Use the actual password when signing in. Each $$ in compose.yaml represents a single $ in the actual password.
If the values are correct, check service status to confirm that graphd is running. In your development machine's terminal, in the deployment directory, view the Graph service logs and check the reported errors:
docker compose logs --tail 100 graphd
Check sample data loading
If loading fails, check the errors and created objects as described in Data loading. You do not need to reload movie after it has loaded successfully. Repeated loads can cause name conflicts.
Verify the query connection
To test the connection separately, select CONSOLE in the NebulaGraph Studio top navigation bar. Paste this statement into the input area and select the run button:
RETURN 1 AS result
It should return a column named result with the value 1. This statement does not depend on sample graph data, so you can use it to check the connection and basic query execution.
Check query results
If a query fails or returns no rows, check the capitalization of graph name movie and node type Movie. Then run these statements one at a time in the same console:
SHOW CURRENT_SCHEMA
The path in the result should be /default_schema. If it differs, run SESSION SET SCHEMA /default_schema to switch back to the default Schema.
SHOW GRAPH TYPES
The result should list graph type movie_type.
SHOW GRAPHS
The result should list graph movie, with graph type movie_type and Schema /default_schema.
If loading was interrupted, the graph's existence does not confirm that its data is complete. Check the errors and existing objects as described in Data loading before continuing. Repeated loads can cause name conflicts.
What's next¶
- Example dataset: movie: View the complete data model.
- Get started with GQL: Create a graph and run CRUD operations: Practice creating a graph and inserting, updating, and deleting data.
- Application tutorials: Use the movie queries in an application.