How to mutate my custom data field

I am unable to get or set my user object custom_data field. I have added the rule for the collection and enabled custom data, but where do I go next

Welcome to the forums @Alfred_Lotsu!

Sorry you are having difficulty - in order for us to help, we need a clear description of the issue, the code you’ve attempted and your troubleshooting. In this case, it’s not clear if you are having the issue in the Realm console or somewhere else. Can you provide more info so we can get a feel for what the issue is?

1 Like

Thanks for the reply.

const mongo = app.currentUser.mongoClient("mongodb-atlas");
    const collection = mongo.db("tree").collection("leaves");

    await collection.insertOne(
        {userID: app.currentUser.id},
    )
    await app.currentUser.refreshCustomData()
    console.log(app.currentUser.customData)

I am hoping that this would match my user object to the custom_data field with the same id, so when I make further changes to my custom_data field, it would apply to my current user.
Any guidance would be very much appreciated

@Alfred_Lotsu In general you’re on the right track.

It’s important that the App Services UI is configured correctly as well. Check the App Users page under the Custom User Data tab in the console to find and configure custom user data settings, including the custom user data cluster, database, and collection and the userId field used to map custom user data documents to users.

Also check the Permissions.

In this case you’re storing their data in the tree->leaves collection which is technically legal but I would suggest a better naming scheme, perhaps a collection name of “users”.

One mistake I’ve made is inconsistent naming so I would also suggest userId for instead of userID.

Check your settings and report back your findings.

Thanks for the reply. I was able to figure it out. The code I attached in the previous reply was in my signup component, at which point “app.currentUser” was still null because it was not verified by logging in. I moved the code to run after logging in and user verification and it is running smoothly now