Hey Fauna team!
Just wondering what the best way is to get the value from an index that returns a single value and not a ref. For example, let’s say I have a collection of documents that have the following:
{
id: string
title: string
}
and I have an index set up to ensure they’re unique:
CreateIndex({
name: 'book-by-id',
source: Collection('books'),
unique: true,
serialized: true,
terms: [{ field: ['data', 'id'] }]
})
And then another index which returns only the title based on ID:
CreateIndex({
name: 'book-title-by-id',
source: Collection('books'),
unique: false,
serialized: true,
terms: [{ field: ['data', 'id'] }],
values: [{ field: ['data', 'title'] }]
})
If I use Get(Match(Index('book-title-by-id'), 'some-id'))
it will get the document, not really what I need. Currently we’ve been doing something like:
Select(0, Paginate(Match(Index('book-title-by-id'), 'some-id')))
Which successfully returns only the title. But this index will always return only one record because unique: true
is set on the book-by-id
index. Is there a way to just get the first value returned, or is this best way to do it?
I couldn’t find any other questions similar, so happy to be pointed in the right direction if this has been asked before.
Thanks heaps!