Querying UUID Type Values in MongoDB

96 Views Asked by At

Documents stored in a collection include a UUID type value when they are inserted and when they are returned from Monger's find-maps function. For example:

{:_id "5515e636314525806f24ceb3"
 :a #uuid "cfda7109-6e50-44c0-b13d-48712f7509a1"}

However when I specify query with this criterion:

(find-maps db collection {:a #uuid "cfda7109-6e50-44c0-b13d-48712f7509a1"})

or this:

(find-maps db collection {:a "cfda7109-6e50-44c0-b13d-48712f7509a1"})

no results are returned. Do I need to use a type converter, or should I just store :a as some other type? Or, perhaps there is some other way?

1

There are 1 best solutions below

1
Tim Clemons On

Try converting using the fromString static method of java.util.UUID:

(ns my.project
  (import [java.util UUID]))

(find-maps db collection {:a (UUID/fromString "cfda7109-6e50-44c0-b13d-48712f7509a1")})