realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

user.customData is not returning data in proper JSON format

Open ahmedmukhtar1133 opened this issue 3 years ago • 4 comments

How frequently does the bug occur?

All the time

Description

After login user.customData should return the data in proper json formats.

But receiving the data in E-JSON format. See stats property:

{
    "_id": "62efedca3587e6e83c0fc675",
    "lastName": "",
    "firstName": "Ahmad",
    "email": "[email protected]",
    "password": "",
    "company": "",
    "optNewsLetter": true,
    "id": "62f013361798f5d543a7fa52",
    "verified": true,
    "acceptedTermsDate": "08/08/2022, 00:30:22",
    "acStatus": null,
    "acId": null,
    "managedUsers": [],
    "stats": {
        "appStartCount": {
            "$numberInt": "13"
        },
        "batchRunExportCount": {
            "$numberInt": "1"
        },
        "testRunCount": {
            "success": {
                "$numberInt": "12"
            },
            "failed": {
                "$numberInt": "2"
            }
        }
    }
}

Expected: It should return data in proper json or should provide toArray() method like mongodb-nodejs package provides

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

const credentials = Realm.Credentials.emailPassword(params.email, params.password)
const user = await app.logIn(credentials)
console.log(user.customData)

Version

1.7.1

What SDK flavour are you using?

Atlas App Services (auth, functions, etc.)

Are you using encryption?

No, not using encryption

Platform OS and version(s)

MacOs

Build environment

Electron: ReactJS, NodeJs

Cocoapods version

No response

ahmedmukhtar1133 avatar Sep 15 '22 20:09 ahmedmukhtar1133

Thanks for reporting this. I believe we have the same issue in the Realm Web SDK.

kraenhansen avatar Sep 16 '22 07:09 kraenhansen

@kraenhansen Any idea when it will be fixed?

ahmedmukhtar1133 avatar Sep 16 '22 15:09 ahmedmukhtar1133

We have the same issue in the Web SDK. I found a work around, but it's not awesome.

import { EJSON } from 'bson';

const appStartCount = EJSON.deserialize(user.customData.stats.appStartCount);

matt2legit avatar Feb 23 '23 00:02 matt2legit

Custom user data can be a generic MongoDB document, and returning BSON data will capture all types.

kneth avatar Feb 23 '23 10:02 kneth