Search code examples
arraysmongodbrealm

MongoDB Realm issue: schema for namespace (tracker.users) must include partition key "_partition"


I'm trying to add a list of friends to each user as a property. But, I don't know why I get this error: MongoDB Realm issue: schema for namespace (tracker.users) must include partition key "_partition". For my project, tasks.users, I have the id, user_id, and name, with the friends list that will contain all three as well.

{
  "title": "User",
  "required": [
    "_id",
    "user_id",
    "name"
  ],
  "properties": {
    "_id": {
      "bsonType": "objectId"
    },
    "user_id": {
      "bsonType": "string"
    },
    "name": {
      "bsonType": "string"
    },
    "_partion": {
      "bsonType": "string"
    },
    "friends": {
      "bsonType": [
        "array"
      ],
      "uniqueItems": true,
      "additionalProperties": false,
      "items": {
        "bsonType": [
          "object"
        ],
        "required": [
          "id"
        ],
        "additionalProperties": false,
        "description": "'items' must contain the stated fields.",
        "properties": {
          "name": {
             "bsonType": "string"
          },
          "id": {
            "bsonType": "objectId"
          },
          "user_id": {
            "bsonType": "string"
          },
          "rank": { "bsonType": "int" },
        }
      }
    }
  }
}

Solution

  • If you are using the BETA MongoDB Ream Sync, your objects need to include a partition key property

    MongoDB Realm uses partition keys to map MongoDB documents in a synced MongoDB Atlas cluster into Realm objects in realms.

    You likely defined a partition key when you set up Sync in the MongoDB Realm console. Every object that you want sync'd need to contain that.

    This is a really good read on how to use partition keys

    Partition Atlas Data into Realms