clojuredatomic

How to find only one record from query in datomic?


I'm doing a query on datomic using datomic.api like the following:

(d/q
  '[:find [(pull ?a [*]) ...]
    :in $ ?title
    :where
    [?a :movie/title ?title]]
 db title)

This query is returning almost the expected value, but as an array, like this:

[ {:db/id 17592186045442, :movie/title "Test", :movie/year 1984, :movie/director #:db{:id 17592186045439 }} ]

I want this query to return only the first match, and not all the results. What I'm doing wrong?


Solution

  • It is documented in the official Datomic documentation:

    Find Spec

    • :find ?a ?b relation (Collection of Lists)
    • :find [?a …] collection (Collection)
    • :find [?a ?b] single tuple (List)
    • :find ?a . single scalar (Scalar Value)