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

Realm v6.0.0 - old entires lost their order and new entries being added at random

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      <!---

      Questions: If you have questions about HOW TO use Realm, please ask on
      StackOverflow: http://stackoverflow.com/questions/ask?tags=realm
      We monitor the realm tag.

      Feature Request: Just fill in the first two sections below.

      Bugs: To help you as fast as possible with an issue please describe your issue
      and the steps you have taken to reproduce it in as much detail as possible.

      -->

      I've recently update to Realm studio 3.11.0 and Realm 6.0.0, it seems that the order of the items in my DB got all mixed up. Adding new items seems to be at random (places them randomly, instead of as last item).

      Edit:
      Just to add, when I updated to 6.0.0, I got "badchangeset" (or similar can't remember the exact wording) inside realm studio, for the opened realm.

      Goals

      Be able to keep the order the items, that are being added.

      <!--- What are you trying to achieve? -->

      Actual Results

      Items seem to be added at random.

      <!--- What happened instead? -->
      <!--- e.g. the stack trace of a crash -->

      Steps to Reproduce

      Connect to a realm and add a few entries.
      <!--- What are steps we can follow to reproduce this issue? -->

      Code Sample

      I can't reproduce it on a new test realm, but it happens on our development one.

      package.json

      {
        "name": "testproject",
        "version": "1.0.0",
        "description": "",
        "main": "index.js",
        "scripts": {
          "test": "echo \"Error: no test specified\" && exit 1",
          "start": "node index.js"
        },
        "keywords": [],
        "author": "",
        "license": "ISC",
        "dependencies": {
          "realm": "^6.0.0"
        }
      }
      
      

      index.js

      const Realm = require('realm');
      
      const realmUsername = 'Username';
      const realmPassword = 'Password';
      const realmServerURL = 'Realm url without https:// or realms://';
      
      const testSchema = {
          name: 'Test',
          properties: {
              id: 'string',
              test: 'string?',
          }
      };
      
      const generateGuid = () => {
          const s4 = () => {
              return Math.floor((1 + Math.random()) * 0x10000)
                  .toString(16)
                  .substring(1);
          }
      
          return `${s4() + s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
      };
      
      
      (async () => {
          const currentCredentials = Realm.Sync.Credentials.usernamePassword(
              realmUsername,
              realmPassword
          );
      
          const user = await Realm.Sync.User.login(
              `https://${realmServerURL}`,
              currentCredentials
          );
      
          const databaseOptions = {
              schema: [testSchema],
              sync: {
                  url: `realms://${realmServerURL}/test`,
                  user
              }
          };
      
          const realm = await Realm.open(databaseOptions);
      
          realm.write(() => {
              realm.create('Test', {
                  id: generateGuid(),
                  test: '1',
              });
      
              realm.create('Test', {
                  id: generateGuid(),
                  test: '2',
              });
      
              realm.create('Test', {
                  id: generateGuid(),
                  test: '3',
              });
          });
      
          realm.objects('Test').forEach(f => {
              console.log(f.test);
          })
      
          console.log('End');
      })();
      
      

      <!---
      Please provide a code sample or test case that highlights the issue.
      If relevant, include your model definitions.
      For larger code samples, links to external gists/repositories are preferred.
      Full projects that we can compile and run ourselves are ideal!
      -->

      Version of Realm and Tooling

      • Realm JS SDK Version: 6.0.0
      • Node or React Native: Node 12.16.3
      • Client OS & Version: Windows 10 Pro 64bit
      • Which debugger for React Native: None

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: