Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set null properties on class instance creation (noisy in mongo db) #1587

Open
olivier5741 opened this issue Aug 16, 2023 · 4 comments
Open

Comments

@olivier5741
Copy link

Is your feature request related to a problem? Please describe.

When I create an instance of a class in Realm studio, all nullable fields I don't fill in are automatically filled in with null value (instead of not filling it). It's a lot of noise when you navigate in Mongo Compass

Describe the solution you'd like

Don't set null fields and have a way to unset a field in the table edition

Describe alternatives you've considered

Script to delete null properties (probably not optimised)

const collectionNames = db.getCollectionNames();

for (const name of collectionNames) {
  var coll = db.getCollection(name);
  var cursor = coll.find();
  while (cursor.hasNext()) {
    var doc = cursor.next();
    var keys = {};
    var hasNull = false;
    for (var x in doc) {
      if (x != "_id" && doc[x] == null) {
        keys[x] = 1;
        hasNull = true;
      }
    }
    if (hasNull) {
      coll.updateOne({ _id: doc._id }, { $unset: keys });
    }
  }
}
@kneth
Copy link
Member

kneth commented Aug 17, 2023

Unfortunately the Realm database only has the concept of null and not undefined as JavaScript.

Can you explain a bit more? Do you change your Realm file in Studio, copy it to your app and synced it to Atlas?

@olivier5741
Copy link
Author

Hi @kneth, I open my app generated realm file with studio then launch the app and edit with studio. It automatically sync. Not sure it's the way to go :). It would be super handy for me to use Realm studio as a CMS.

If I could find a way to connect Realm studio directly to Atlas that would mean I could ask a non-developer to use it as a CMS : quite hacky but effective. I'm trying to tweak Realm studio to be a bit more CMS user friendly :)

@kneth
Copy link
Member

kneth commented Aug 23, 2023

@olivier5741 When you are using device sync, you will be able to view and editor your data in Atlas using Compass.

@olivier5741
Copy link
Author

Realm studio is type aware and relationship type aware and helps you in that way. Compass isn't ... (or there is stuff I don't know :), if you define a json schema in validation will the editor understand this in Compass ). It's faster to create objects in Realm studio than Compass (instant commit or you can choose to use a transaction -> pretty cool :) ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants