Collections
db.collections.get returns read-only snapshots for collections. You can keep chaining filters or use normal array methods.
These examples use a small fixture that resets for every run. Your application still uses its own Realm database.
all
Returns all matching collections in a regular array.
return db.collections.get
.all()
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))toArray
Returns all matching collections in a regular array.
return db.collections.get
.toArray()
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))first
Returns the first matching collection, or undefined.
return db.collections.get
.first()?.Namecount
Counts all matching collections, even when a limit is set.
return db.collections.get
.count()limit
Limits how many collections elements are accessed.
return db.collections.get
.limit(1)
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))sortedBy
Sorts collections by a database field.
return db.collections.get
.sortedBy('Name')
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))autoEdit
Starts an edit session that buffers changes to matching collections. Commit or roll them back when you are done.
const session = db.collections.get
.limit(1)
.autoEdit()
const length = session.length
session.rollback()
return lengthcommit
Saves the pending changes.
const session = db.collections.get
.limit(1)
.autoEdit()
const length = session.length
session.commit()
return lengthrollback
Discards the pending changes.
const session = db.collections.get
.limit(1)
.autoEdit()
const length = session.length
session.rollback()
return lengthwrite.delete
Deletes every matching collection in one transaction.
return db.collections.get
.limit(1)
.write.delete()write.update
Applies a typed patch to every matching collection.
return db.collections.get
.limit(1)
.write.update({ Name: 'Example' })byId
Finds collections where ID matches the supplied value. You can chain more filters on the result.
return db.collections.get
.byId('66666666-6666-4666-8666-666666666666')
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))byLastModifiedAfter
Finds collections where last modified is after the supplied date. You can chain more filters on the result.
return db.collections.get
.byLastModifiedAfter(new Date('2024-01-01'))
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))byLastModifiedBefore
Finds collections where last modified is before the supplied date. You can chain more filters on the result.
return db.collections.get
.byLastModifiedBefore(new Date('2024-01-01'))
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))byName
Finds collections where name matches the supplied value. You can chain more filters on the result.
return db.collections.get
.byName('Favorites')
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))byNameContains
Finds collections where name contains the supplied value. You can chain more filters on the result.
return db.collections.get
.byNameContains('Fav')
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))sortedByLastModified
Returns collections ordered by last modified.
return db.collections.get
.sortedByLastModified(true)
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))sortedByName
Returns collections ordered by name.
return db.collections.get
.sortedByName(true)
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))withBeatmap
Finds collections related to the supplied beatmap.
return db.collections.get
.withBeatmap('b'.repeat(32))
.map(item => ({
name: item.Name,
beatmaps: item.BeatmapMD5Hashes.length,
}))