Source: https://dev-docs.nebula-graph.io/v5.3.2/get-started/first-query/ Documentation version: v5.3.2 # 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](https://dev-docs.nebula-graph.io/v5.3.2/get-started/deploy/) to start NebulaGraph Database Developer Edition and the supplied NebulaGraph Studio. - Have your current `root` password ready. ## 1. Sign in to NebulaGraph Studio On the development machine running Docker, open [http://127.0.0.1:7001](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://:7001`. Replace `` 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. 1. Select the SCHEMA tab in the top navigation bar. 2. Check that `default_schema` is selected at the top of the left sidebar. 3. Select Use Demo Dataset in the center of the page. 4. Wait for loading to finish. On success, the `movie_type` graph 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](https://dev-docs.nebula-graph.io/v5.3.2/get-started/first-query/#select-graph) 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 movie` specifies the graph for this query. - `MATCH` finds matching nodes. `@Movie` specifies the movie type, and `{id: 3}` specifies the movie ID. An ID distinguishes movies with the same name. - `RETURN` selects properties to display; `AS` names 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](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/dql/clauses/use-graph/) 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](https://dev-docs.nebula-graph.io/v5.3.2/utilities/ngql/usage/), 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](https://dev-docs.nebula-graph.io/v5.3.2/get-started/deploy/#stop-start). Next time, [sign in to NebulaGraph Studio](https://dev-docs.nebula-graph.io/v5.3.2/get-started/first-query/#connect) and continue from [step 3](https://dev-docs.nebula-graph.io/v5.3.2/get-started/first-query/#select-graph) 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 1. In the development machine's terminal, open the directory containing `compose.yaml` and run: ```` docker compose exec ngql ngql --host graph-cluster --port 9669 --user root ```` The first `ngql` is the Compose service name; the second is the client command inside the container. Keep `graph-cluster:9669`, the query address on the container network. 2. At the `Password` prompt, enter the current `root` password and press Enter. 3. If `movie` has not been loaded in `/default_schema`, run this command. Skip this step if loading has already succeeded. ```` :play movie ```` The client displays `Playing dataset: movie...` at the start and `Play dataset: movie done.` on success. If loading fails, inspect the created objects and errors as described in [Data loading](https://dev-docs.nebula-graph.io/v5.3.2/get-started/dataset/#load-behavior). Then run the examples from [Find a movie](https://dev-docs.nebula-graph.io/v5.3.2/get-started/first-query/#select-graph) and [Find the movie's actors](https://dev-docs.nebula-graph.io/v5.3.2/get-started/first-query/#5_find_the_movies_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://:19669/ui/console` Replace `` 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](https://dev-docs.nebula-graph.io/v5.3.2/get-started/first-query/#select-graph) 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`](https://dev-docs.nebula-graph.io/v5.3.2/get-started/first-query/#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](https://dev-docs.nebula-graph.io/v5.3.2/get-started/deploy/#studio-troubleshooting). - The page opens, but sign-in fails: Check the address, port, username, and actual password against [step 1](https://dev-docs.nebula-graph.io/v5.3.2/get-started/first-query/#connect). To change an existing instance's password, follow [Change an existing instance's root password](https://dev-docs.nebula-graph.io/v5.3.2/get-started/deploy/#change-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](https://dev-docs.nebula-graph.io/v5.3.2/get-started/deploy/#check-services) 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](https://dev-docs.nebula-graph.io/v5.3.2/get-started/dataset/#load-behavior). 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](https://dev-docs.nebula-graph.io/v5.3.2/get-started/dataset/#load-behavior) before continuing. Repeated loads can cause name conflicts. ## What's next - [Example dataset: movie](https://dev-docs.nebula-graph.io/v5.3.2/get-started/dataset/): View the complete data model. - [Get started with GQL: Create a graph and run CRUD operations](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/first-steps/): Practice creating a graph and inserting, updating, and deleting data. - [Application tutorials](https://dev-docs.nebula-graph.io/v5.3.2/app-development/): Use the movie queries in an application.