Get the count/length of a Realm List
Undefined is not an object
Meta.schema = {
name: 'Meta',
primaryKey: 'id',
properties: {
id: 'string',
fileData: 'FileData[]'
}
}
let meta = realm.objects('Meta').filtered('id = $0', '123')
let fileData = meta.fileData
console.log(fileData.length) // should output an integer
realm.objects('Meta').filtered('id = $0', '123') returns a _collection_ of objects that match the given predicate. When you're doing:
let meta = realm.objects('Meta').filtered('id = $0', '123')
let fileData = meta.fileData
You're asking for the fileData property on this collection, which isn't a property that exists. What you'd want to do instead is to retrieve an element from the collection, then access its fileData property.
Or since id is your primary key you could just take the more direct route and use Realm.objectForPrimaryKey:
let meta = realm.objectForPrimaryKey('Meta', '123')
Most helpful comment
realm.objects('Meta').filtered('id = $0', '123')returns a _collection_ of objects that match the given predicate. When you're doing:You're asking for the
fileDataproperty on this collection, which isn't a property that exists. What you'd want to do instead is to retrieve an element from the collection, then access itsfileDataproperty.Or since
idis your primary key you could just take the more direct route and useRealm.objectForPrimaryKey: