Hi!
I followed steps in stitch documentation: Cutom User Data
In the Users section of Mongo Stitch panel I enabled custom data. I chose database, collection ( users ) and stated User ID Field to be userId . Then I deployed changes.
I copied the user’s id and inserted the following document to the users collection db.users.insertOne({userId: ObjectId('copied_id'), description: "something"}).
The document exists and I can see it when querying the collection. The userId field has correct ObjectId() value (in the correct ObjectId format).
Nonetheless, when I log in with the user (I log in via Node.js SDK) the customData property of the userObject is empty. It should contain at least the description field.
What can be the reason? Has anyone had a similar problem?
Cheers,
Eryk
Hi Folks – Sorry to hear that you’re having trouble accessing custom user data within Stitch. After scanning the documentation looks like there might be a typo in the sample code, we believe –
We’ve filed a ticket to update our documentation. If that doesn’t resolve your issue, would you mind either posting or sending me directly an example document from your users collection (with any PII removed).
here is what I did to retrieve the custom data
1- create a function in stitch functions.
the function you create looks like this:
exports = function(arg){
return context.user.custom_data;
};
2- you give it a name example: myFunction
3.you call the function inside your code like so:
const client = Stitch.defaultAppClient;
client.callFunction(‘myFunction’).then(result=>result).catch(err=>err)