question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"realm.objects()" will return an number

See original GitHub issue

Goals

Get all results

Expected Results

realm.objects('Video') should return an array

Actual Results

A number is returned, almost half, looks like not the count of the result.

Steps to Reproduce

Code Sample

var realm;

this.allVideos = () => {
  console.log(`this.allVideos: ${this}, ${this.realm}`);

  const videos = this.realm.objects('Video');
  if (videos.length === undefined) {
    console.log(`!!!! Find a Realm\'s bug: videos should be array but it is ${videos}`);
    return null;
  } else {
    console.log(`allVideos: ${videos.length} ${videos}`);
  }

  return videos;
}

My log

!!!! Find a Realm's bug: videos should be array but it is 1

Version of Realm and Tooling

  • Realm JS SDK Version: 2.2
  • Node or React Native: 0.29
  • Client OS & Version: iOS 11
  • Which debugger for React Native: Chrome

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
dmitryskorbovenkocommented, Oct 9, 2018

Hello, just want to share with you how I fixed this issue:

I have replaced all my addListener(this.listener); with the following addListener((results)=>setImmediate(this.listener, results));

Realm guys, I guess this should give you hint where to find the bug Hopefully it will save a day someone )))

2reactions
hcliffcommented, Nov 8, 2018

Ran into this as well. Can confirm it was occurring while debugging.

Solved by converting the RealmObject into a plain object immediately.

const objs = realm.objects(MessageSchema.name).map(function(obj){
  return {
    id: obj.id,
    name: obj.name
    ...
  }
});
console.log("objects", objs);

if you’re relying on realm for dynamic models/collections obviously this won’t help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Realm.Object - MongoDB
Returns : Realm.Results the objects that link to this object. Since: 1.9.0. linkingObjectsCount() number. Returns the total count of incoming links to this ......
Read more >
Realm.objects() return empty objects on React Native
Realm does define a toJSON() function on Result objects. This can be useful for coercing the object into the actual value. instead of:...
Read more >
Class: Collection - Realm
The number of objects in the collection. ... entries() Iterator ... If this function returns true for every object, then this method will...
Read more >
Realm Database on Android: Getting Started
Use where(PetRealm::class.java) to retrieve PetRealm objects. findAll() executes the query and returns every PetRealm object. Map PetRealm ...
Read more >
[Solved]-How to observe objects count on realm db-swift
Coding example for the question How to observe objects count on realm db-swift. ... Error> { return changeNotificationsRaw().flatMap(.concat) { realmChange ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found