const WORKPLAN_SCHEMA = {
name: ‘workplans’,
properties: {
_id: “objectId”,
status: “int”,
zoneId: “???”, <—<< array
},
primaryKey: ‘_id’
};
We need to declare array and make relationship between this array with other tables.
------> like that
const WORKPLAN_SCHEMA = {
name: ‘workplans’,
properties: {
_id: “objectId”,
status: “int”,
zoneId: [
{
zoneId: “objectId” >>----> relation with zone table >>-----> { _id: “objectId”, zoneName: “test_1” }
},
{
zoneId: “objectId” >>----> relation with zone table >>-----> { _id: “objectId”, zoneName: “test_1” }
}
]
},
primaryKey: ‘_id’
};
Hi, we use JSON Schema so please see here for that: array — Understanding JSON Schema 2020-12 documentation
So you probably want something like:
const WORKPLAN_SCHEMA = {
name: ‘workplans’,
properties: {
_id: {bsonType: “objectId”},
status: {bsonType: “int”},
zoneId: {bsonType: “array”, items: {bsonType: "objectId}},
}
And then you can add that this is a relationship in the UI in the relationships tab of the schema editor.
If, you are trying to use the JS SDK and define your schema model there (not sure as you didnt give much information about where the schema you give here is being defined), then please see this guide: https://www.mongodb.com/docs/realm/sdk/node/examples/define-a-realm-object-model/#define-a-to-many-relationship-property
Ian_Ward
(Ian Ward)
May 24, 2022, 11:58am
4
That’s not how you define a relationship on the client - in the doc Tyler linked the example here shows how Person can have a list of Dogs
const Person = {
name: "Person",
properties: {
name: "string",
birthdate: "date",
dogs: "Dog[]"
}
};
const Dog = {
name: "Dog",
properties: {
name: "string",
age: "int",
breed: "string?"
}
};
If you’re having trouble setting up the schema you may want to just use developer mode, that way, you just need to setup the schema on the client side and it will be automatically replicated on the Server. -
of type ‘array’ has unknown object type ‘friendList’ i getting this error.
Ian_Ward
(Ian Ward)
May 25, 2022, 1:20pm
8
If you take a look at the error message you will see that your names are mismatched - you need to correct that.
Ian_Ward
(Ian Ward)
May 25, 2022, 6:54pm
10
I can’t see the error message - can you paste it in here? Also, can you please share your Realm App UI URL (the URL of the Realm App in the browser) - so I can take a look at the logs ?
Ian_Ward
(Ian Ward)
May 25, 2022, 7:39pm
12
Are you wiping the local state on the device as you change the schema? You need to do that because you are making breaking changes. Also I think friendList needs to have a valid _id field if it is a standalone object
The Realm Server-side Cloud logs would tell us more as well
I dont know where we found the cloud logs. Can you send me the path.