# Figure out what's in a Database

**URL:** <https://discuss.dgraph.io/t/figure-out-whats-in-a-database/2075>\
**Category:** Users\
**Created:** [December 29, 2017, 6:13am UTC](https://discuss.dgraph.io/t/figure-out-whats-in-a-database/2075 "2017-12-29T06:13:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomsaleeba](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tomsaleeba](https://discuss.dgraph.io/u/tomsaleeba)\
**Post date:** [December 29, 2017, 6:13am UTC](https://discuss.dgraph.io/t/figure-out-whats-in-a-database/2075/1 "2017-12-29T06:13:52Z")

</div>

Generally, I’m interested how to explore a Dgraph database when you don’t know what is in there. Suppose someone has given you access to a Dgraph instance, what’s the first query you run to start working out what’s in there? Or is GraphQL± not the tool for the job and you should find the schema or get the information out-of-band?

My specific case is I’ve used the Bulk loader to load some RDF and let it construct the schema itself. The RDF looks like:

```auto
<http://example.com#literalbagcontainer1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com#THINGY> .
<http://example.com#literalbagcontainer1> <http://example.com#linked_to> "bar" .
<http://example.com#literalbagcontainer1> <http://example.com#linked_to> "foo" .

```

At this stage, I’ve got a few problems:

1. I don’t know if the property name was loaded with the full URI like [http://example.com#linked\_to](http://example.com#linked_to) or shortened somehow
2. if full URIs are used, I can’t figure out how to escape the names in a GraphQL± query. Any queries that use the full URI complain about the : (colon) character. I’ve tried escaping with single quotes, double quotes and backticks but none seem to work. Google queries for “dgraph escape” aren’t yielding anything either.
3. I can’t find the generated schema. I’m running in Docker and I’ve done a `docker exec` into the container to look around but can’t find a schema

Solutions to my specific case are appreciated but I’m more interested in the general skill of exploring a Dgraph DB with no prior knowledge. In a relational world I’d get some tables names, describe them then start doing some `SELECT *` queries to get a feel for the DB. In other NoSQL DBs there’s typically some wildcard type queries where you can start looking at some data, any data! In GraphQL± I’m stuck, I can’t figure out a SELECT \* type query.

I’ve tried guessing at UIDs but no matter what UID I used, I get a response but without any edge names:

```auto
{
  f(func: uid(0x00)) {
    uid
    linked_to # here I'm guessing the RDF property was shortened
  }
}

```

Thanks for the help  
Tom

---

<div class="post-metadata">

**Author:** ![peter](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/peter/32/574_2.png) [@peter](https://discuss.dgraph.io/u/peter)\
**Post date:** [January 2, 2018, 12:27am UTC](https://discuss.dgraph.io/t/figure-out-whats-in-a-database/2075/2 "2018-01-02T00:27:47Z")

</div>

When exploring unknown data, I would recommend the following steps:

1. First, query the schema. [https://docs.dgraph.io/query-language/#querying-schema](https://docs.dgraph.io/query-language/#querying-schema)
2. Then start looking at some of the nodes. E.g. use the `has` function to find all nodes with a particular predicate (discovered from the schema query). [https://docs.dgraph.io/query-language/#has](https://docs.dgraph.io/query-language/#has)
3. Next step would be to start expanding the graph using `expand(_all_)` and start to explore the relationships.

GrahpQL± and Ratel are great for this, since Ratel helps to visualise the relationships (which would otherwise be harder to understand just looking at the raw JSON responses).

For predicate names, I would recommend using simplified predicate names, e.g. `type` and `linked_to`. You would have to pre-process your data, but it will make everything much easier for you. Although, if you really want to use URIs for predicates, you should be able to escape using a backslash.

---

<div class="post-metadata">

**Author:** ![tomsaleeba](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tomsaleeba](https://discuss.dgraph.io/u/tomsaleeba)\
**Post date:** [January 2, 2018, 4:41am UTC](https://discuss.dgraph.io/t/figure-out-whats-in-a-database/2075/3 "2018-01-02T04:41:09Z")

</div>

Hi Peter,  
thanks for the helpful tips. They’re exactly what I needed.

I don’t want to use URIs for predicates, that’s just what my RDF data has in it and I was trying to quickly get Dgraph up and running with my data to take it for a test drive. If I’m going to be pre-processing the RDF, I’ll strip the names down to simple ones like you suggest.

For what it’s worth, I can’t get that backslash escaping to work. A query like this works, so we know it’s a good starting point:

```auto
{
  me(func: has(age)) {
    expand(_all_)
  }
}

```

Then I change the predicate name to a full URI, which we expect to fail:

```auto
{
  me(func: has(http://example.com#linked_to)) {
    expand(_all_)
  }
}

```

…and we get our error:

```auto
Expected arg after func [has], but got item lex.Item [14] ":"

```

So then I backslash escape the `:` so the query is:

```auto
{
  me(func: has(http\://example.com#linked_to)) {
    expand(_all_)
  }
}

```

but then we get a different error:

```auto
Expected arg after func [has], but got item lex.Item [1] "while lexing {\n me(func: has(http\\://example.com#linked_to)) {\n expand(_all_)\n }\n}: Unrecognized character in inside a func: U+005C '\\'"

```

It appears to be unhappy with the backslash. It won’t be a problem when I stop using full URIs but I wanted to highlight that it didn’t work for me.

Regards  
Tom

---

<div class="post-metadata">

**Author:** ![peter](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/peter/32/574_2.png) [@peter](https://discuss.dgraph.io/u/peter)\
**Post date:** [January 2, 2018, 7:19am UTC](https://discuss.dgraph.io/t/figure-out-whats-in-a-database/2075/4 "2018-01-02T07:19:00Z")

</div>

> [@tomsaleeba](#):
>
> It appears to be unhappy with the backslash. It won’t be a problem when I stop using full URIs but I wanted to highlight that it didn’t work for me.

Ah, I was wrong about backslash working to escape. In that case, it _does_ appear that it’s not possible to have `:` in a predicate name.

---

<div class="post-metadata">

**Author:** ![peter](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/peter/32/574_2.png) [@peter](https://discuss.dgraph.io/u/peter)\
**Post date:** [January 3, 2018, 12:30am UTC](https://discuss.dgraph.io/t/figure-out-whats-in-a-database/2075/5 "2018-01-03T00:30:17Z")

</div>

I just found out the proper answer to this: If you wrap the predicate in angle brackets, you can have `:` in the query. E.g. `<two:words>`.

---

<div class="post-metadata">

**Author:** ![tomsaleeba](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tomsaleeba](https://discuss.dgraph.io/u/tomsaleeba)\
**Post date:** [January 3, 2018, 12:51am UTC](https://discuss.dgraph.io/t/figure-out-whats-in-a-database/2075/6 "2018-01-03T00:51:24Z")

</div>

Thanks for looking that up @peter.

In hindsight it makes perfect sense, it’s similar to how SPARQL handles URIs.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [February 2, 2018, 12:51am UTC](https://discuss.dgraph.io/t/figure-out-whats-in-a-database/2075/7 "2018-02-02T00:51:40Z")

</div>

Closed on February 2, 2018, 12:51am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
