Skip to content

useMongocampReferenceOptions ​

The choices of the reference picker of MongocampCollectionData (server 2.4 refs, plan 32): searches the target collection of a declared reference and names the ids a form holds. See Declared collections.

ts
const { search, label, canPick, loadPermission } = useMongocampReferenceOptions()
const ref = declaration.value!.refs[0]!                       // { field: 'customerId', collection: 'customers', many: false }
await loadPermission(ref)
if (canPick(ref)) {
  const options = await search(ref, 'gra')                   // [{ value: '6b0d…', label: 'Grace Hopper', description: '6b0d…' }]
  const names = await label(ref, ['6b0dfe9486b3e443811024ef']) // Map(id → option | null)
}
ReturnDescription
search(ref, term, { signal? })The target's documents whose name / title / label / email contain term (case-insensitive; a hex term also matches the start of the id), at most 20, sorted by name — all of them for an empty term. Rejects when the request fails or is aborted
label(ref, ids, { signal? })Map<hex, ReferenceOption | null> for the 24-hex ids: one request for the ids not known yet; null = the target has no document the user may read for it. Never throws (a failure leaves the ids out)
canPick(ref)Read grant on the target (fail-open like useMongocampPermissions); false for a target in another database
loadPermission(ref)Asks the target's grant once, so canPick answers from the server

Labels (also those a search found) are cached per target and signed-in user in a shared useState. Pure helpers in utils/references.ts: pickerQuery, pickerOption, refFilter(field, ids) (the Lucene filter of a declared reference, server 2.6), idsFilter, referencesTo(declaration), collectionDataLink(collectionsPath, collection, filter?).

Released under the MIT License.