Stitch: Can't make custom user data to appear in userObject.customData

I followed steps in stitch documentation:
Cutom User Data

  1. 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.

  2. I have a created and confirmed user.

  3. I copied the user’s id and inserted the following document to the users collection db.users.insertOne({userId: ObjectId('copied_id'), description: "something"}).

  4. 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?

+1 having this problem too. I’ve reached out to support and will post their reply here also.

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 –

const speaksEnglish = user.profile.customData.primaryLanguage === "English";

Should be –

const speaksEnglish = user.customData.primaryLanguage === "English";

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).

same issue here… pebcak :confused:

I fixed it by setting userId as String, not ObjectId.
(not seen in doc btw)

Hoping it’s not too late :wink:


here is what I did to retrieve the custom data :slight_smile:
1- create a function in stitch functions.
Capture du 2020-06-01 13-12-44

the function you create looks like this:
exports = function(arg){

return context.user.custom_data;

2- you give it a name example: myFunction call the function inside your code like so:
const client = Stitch.defaultAppClient;

I hope this answers your questions, good luck :four_leaf_clover: :slight_smile:

Changing from ObjectId to String worked for me as well, thanks!