Fork me on GitHub
#xtdb
<
2019-12-02
>
sjharms06:12:55

I want to find all documents with a certain :crux.db/id prefix, what is the best practice? Ie (crux/q (crux/db node) '{:find [?e] :where [[?e :crux.db/id ?id] [(clojure.string/starts-with? ?id ":myprefix")]]})

refset07:12:21

Hi @U5JQAQE4X! Unfortunately there is no way to do this efficiently - is there a reason why you can't introduce a new attribute?

sjharms16:12:13

I think I have a attribute which works already, thanks for the idea! I just am doing some greenfield / hobby work with Crux and wanted to understand how to interact, so this helps

refset16:12:22

Ah okay, no problem - good question! :)

erik13:12:32

is it something that would work on Datomic though?

refset01:12:18

@UECLGBLES hey! I think with Datomic you could use the raw AVE index to jump straight to a prefix range and retrieve a set of db.unique/identity values. An equivalent is not currently possible in Crux due to: 1) keywords are hashed in the indexes so such values (including usage as :crux.db/id) won't end up sorted alphanumerically (see codec.clj) 2) you cannot access the the raw indexes - even if you could there could well be a lot more processing cost required than with Datomic due to the extra time dimension (depending on the shape and size of your data history)

✔️ 4
erik21:12:49

thanks for the reply!

🙂 4