First Query

In Datomic, you write queries in Datalog to find out facts about your database.

This section assumes you're continuing from the first transaction section.


You can query for the fact you just created. Queries act against an immutable database value. Call the db function to get the most recent database value:

(def db (client/db conn))

The following query will find all entities in the system with the doc string "hello world":

(<!! (client/q conn {:query '[:find ?e :where [?e :db/doc "hello world"]] 
                :args [db]}))

Datalog query is flexible and powerful, and you can issue many types of queries. The following query, for example, returns the count of all entities in the database that have values for the :db/doc attribute.

(<!! (client/q conn {:query '[:find (count ?e)  :where [?e :db/doc]]
                :args [db]}))

Next: Tutorial