Hi, I have been trying to setup Realm Sync in a NodeJS IoT Application.
I have correctly connected to my database in my Atlas cluster and selected Partition Key as userId
. Next my Permissions for both read and write are defined as:
{
"%%partition": "%%partition"
}
My schema in the NodeJS client app is defined as:
export const AccelerometerReadingsSchema = {
name: 'AccelerometerReadings',
properties: {
_id: 'objectId',
userId: 'string',
nodeId: 'string',
readings: 'string[]',
timestamp: 'date'
},
primaryKey: '_id'
};
Next openRealm
and getRealm
look like this:
async function openRealm(partitionKey: string): Promise<Realm> {
const config = {
schema: [AccelerometerReadingsSchema],
sync: {
user: users.getAuthedUser(),
partitionValue: partitionKey
}
};
return Realm.open(config);
}
export const getRealm = async (partitionKey: string) => {
if (realms[partitionKey] == undefined) {
realms[partitionKey] = openRealm(partitionKey);
}
return realms[partitionKey];
};
Then I simply write to the realm in my app:
const writeToRealm = async (
userId: string,
nodeId: string,
readings: Array<string>,
timestamp: Date
) => {
const realm = await getRealm(`user=${users.getAuthedUser().id}`);
let result;
realm.write(() => {
result = realm.create('AccelerometerReadings', {
userId,
nodeId,
readings,
timestamp
});
});
};
The app or the Realm logs show no errors, the app starts up fine, the user is properly logged in but the data is never written to MongoDB Atlas.
Any hints what I am doing wrong here?