0

I am new to MongoDB Realm, however had some experience with MongoDB.

Before any comments about the same problem, I already have been to all discussions and nothing have helped me yet.

I have consulted these discussions:

Android BAD_CHANGESET(realm::sync::ProtocolError:212): Bad changeset (UPLOAD) Error

Keep getting BadChangeset Error

But sadly, either the mentioned solutions doesn’t work for me or I am not able to understand those.

I am currently using Realm in Nodejs. I have partition key as restroName while activating sync. But constantly I keep getting 212 error while I connect using:

const realm = new Realm({
        schema:[ItemSchema],
        sync:{
            user:user,
            partitionValue: user.id,
        }
    })
failed to validate upload changesets: SET instruction had incorrect partition value for key “restroName” (ProtocolErrorCode=212)

When I try to use partionValue: “anything”, it gives:

user does not have permission to sync on partition (ProtocolErrorCode=206)

So I assume it needs to be the user.id on the partitionValue but I want to store data in the realms with restroName.

Also I always clear the realm data (wipe it) before I make changes.

I hope I can get help.

Update: My Item Schema looks like this:

const ItemSchema = {
    name: "item",
    properties: {
      _id: "objectId",
      restroName: "string",
      details:  "string?",
      name: "string?",
      status: "string?",
      price: "string?"
    },
    primaryKey: '_id'
}
  • How did you configure your MongoDB Realm Cloud instance? Are you using developer mode? – geisshirt Dec 07 '20 at 16:07
  • The question is a bit unclear but perhaps you changed the name of your partition key? Not the *value* but the actual name. Realm suggests using something like `_partitionKey`. What does `ItemSchema` look like? – Jay Dec 07 '20 at 20:23
  • @geisshirt I am not using developer mode and I have mentioned earlier how I configured Realm instance in node.js. In Realm website, I set the partitionKey as restroName and the permissions set to users can read and write their own data. – Maneez Paudel Dec 11 '20 at 11:11
  • @Jay the item schema looks like `const ItemSchema = { name: "item", properties: { _id: "objectId", restroName: "string", details: "string?", name: "string?", status: "string?", price: "string?" }, primaryKey: '_id' }` And pardon me, I didn't get your point of using _partitionKey. – Maneez Paudel Dec 11 '20 at 11:12
  • Please don't put code and structures in comments and they are very hard to read. Please update the *question* with that info so you can format it to be readable. – Jay Dec 11 '20 at 15:58
  • @Jay I have updated the question, please take a look – Maneez Paudel Dec 13 '20 at 07:23
  • There's not enough info in the question to pose a formal answer but it looks like there are some setup issues. The partition the realm object is connecting to uses the (assumed) currently auth'd users uid. But that doesn't appear to match what you want to use as the partition of `restroName`; however without more code, I am just guessing. May I suggest you re-read the [Realm Sync Getting Started Guide](https://docs.mongodb.com/realm/tutorial/nodejs-cli#c.-connect-to-your-mongodb-realm-app) and implement *that* code to connect and read realm? It's straightforward and may resolve the issue. – Jay Dec 13 '20 at 14:19
  • @Jay by reading the documentation, it couldn't give solution to my problem. The documentation gives answer to very simple app. But I solved it using custom data for the users. Thank you for your help. – Maneez Paudel Dec 15 '20 at 07:41

1 Answers1

0

The problem raised because I messed partitionKey as user id and restroName. The way I solved it was I kept the partitionKey as restroName and under permissions I kept the template none and set partitions for read and write in realm as :

{
  "%%partition": "%%user.customData.restroName"
}

I consulted here to enable custom data.