Schema default values ignored when creating object



in my model I have properties that are mandatory but I would like to provide a default value. Realm node docs state that we can use the default attribute when creating the schema.
Here is model example :

        name: 'Scenario',
        primaryKey: 'uuid',
        properties: {
            uuid: 'string',
            name: 'string',
            imageUrl: { type: 'string', default: '' },
            description: 'string?'

When I try to create/insert an object by giving only the uuid and name :

realm.write(() => {
    var uuid = require('node-uuid');
    realm.create("Scenario", {uuid:uuid.v1(), name:"scenario1"});

I get this error : Error: Missing value for property ‘Scenario.imageUrl’.

Nullable values are not mandatory but values with defaults are ?
Am I understanding this wrong ?



@mbritto Are you setting up the schema properly? Everything you showed is fine. A thing that commonly trips people up with defaults in JS is that they aren’t persisted in the file, while everything else in the schema is.
So you can open an existing file without specifying the schema and everything but default values will work fine


Sorry @ianward, I’ve just noticed your answer.
I thought I was setting up the schema correctly, I have a Schema.js file that looks like this :

module.exports = [
// ...
        name: 'App',
        primaryKey: 'uuid',
        properties: {
            uuid: 'string',
            name: 'string',
            status: 'string',
            iconUrl: { type: 'string', default: '' },
            storeDescription: 'string?',
            keywords: 'string?',
            heroImageUrl: 'string?',
            scenarios: 'Scenario[]',
            pages: 'Page[]',
            menuItems: 'MenuItem[]'

Then I have a RealmManager.js file that looks like this :

const Schema = require('../data/Schema');
class RealmManager {
    constructor() {
        this.realm = undefined;
// ...
    async createRealm (user, syncUrl) {

        const config = {
            sync: {
        this.realm = await;
        return this.realm
// ...

Are you telling me that I shouldn’t put my default values in the Schema.js file ? Where should I put those ?