Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-470

Improve the output from console.log of objects and collections on Node.js

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      Goals

      Using console.log during debugging is a fairly common practice and the output of calling this on an object or collection from a Realm should be informative.

      Expected Results

      I would expect that logging a Collection of objects (such as Results) would give information on the type of items in the collection, the size of the collection and perhaps a preview of the first couple of elements in the collection. As a reference, calling console.log on an array and objects yields respectively:

      console.log(a);
      // [ { name: 'Alice' }, { name: 'Bob' }, { name: 'Charlie' } ]
      
      console.log(a[0])
      // { name: 'Alice' }
      

      Actual Results, Steps to Reproduce & Code Sample

      const Realm = require('realm');
      const realm = new Realm({ schema: [{ name: "Person", properties: { name: "string" } }] });
      realm.write(() =>{ realm.create('Person', { name: "Alice" }); });
      const persons = realm.objects("Person");
      console.log(persons)
      // Results {}
      console.log(persons[0])
      // Person { [Symbol(_external)]: [External] }
      

      In addition to this, in the Node.js REPL, when executing an expression the REPL prints its value, for a collection, this prints:

      Proxy [ Results {}, {} ]
      

      All of the output above have very limited value to a user while debugging their code.

      NOTE: https://nodejs.org/dist/latest-v12.x/docs/api/util.html#util_custom_inspection_functions_on_objects might come in handy when solving this.

      Version of Realm and Tooling

      • Realm JS SDK Version: 5.0.0
      • Node or React Native: Node.js
      • Client OS & Version: Tested on MacOS
      • Which debugger for React Native: None

            Assignee:
            Unassigned Unassigned
            Reporter:
            kraen.hansen@mongodb.com Kræn Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: