Realm Device Sync: Expected value to be a string, got undefined (Next JS 13)

Hello community,

I’m encountering an error in my application related to Realm Sync. I’m attempting to write data to Realm, specifically creating a Study object with a nested StudyConfig object. However, I’m facing the following error:

Error: Expected value to be a string, got undefined

realm.write(() => {
    realm.create(, {
        studyConfig: studyConfigData.studyConfig || {}, 

In addition, here’s the Study model:

const StudySchema = {
    name: "Study",
    properties: {
        _id: "string",
        studyConfig: { type: "object", objectType: },
    primaryKey: "_id",

I’ve added debug statements to log the data before the write operation, but I can’t identify which property is causing the issue.

I would greatly appreciate any insights or suggestions on how to troubleshoot and resolve this error. If anyone has encountered a similar issue with Realm Sync or has expertise in debugging Realm errors, your assistance would be invaluable.

Thank you for your time and support!

Hi. I would suspect that the issue is that is undefined. Can you add some logging to that value possible? Is there a change it is supposed to be studyConfigData.studyConfig._id?

Hi, will this suffice?

What is the schema for StudyConfigSchema?

It is this one

Got it, its a bit tough to evaluate this frankly. What could be helpful is to either:

  1. Send the full document and all of the schemas associated with this object (all embedded schemas)
  2. Insert the document into MongoDB if you have Device Sync running. The translation process should reject it with an error (I am assuming) and the error should tell you which field is the problem.

Thank You so much for taking the time out to reply.

I was eventually able to overcome this issue by embedding my schemas using (embedded: true) which allowed me to create them without the need for a primary key. I then combined all the schemas into one major schema with a primary key to align with the data I was passing in. Fortunately, this solved my issue.