1

I am using collection2 with meteor to set default values. However when i run the method Meteor.call('commands.insert', {}) on the client, it just sets new document's ID, and only when the result from server comes it replaces the document with the right value. Actually, autoValue function runs on client because when i console.log there it logs (also tried defaultValue), but it does not do anything, does no modifications, nor unique: true is working, any property specified in the schema

server

export const Commands = new Mongo.Collection('commands')

Commands.schema = new SimpleSchema({
designation: {
    type: String,
    autoValue: function() {
        console.log("inssssssssssssssssssseeeeeeeeeeeeeeeeeeeeeeert")
        if (this.isInsert) {
            return "Untitled"
        }
    },
    unique: true
},
name: {
    type: String,
    autoValue: function() {
        if (this.isInsert) {
            return ""
        }
    },
    optional: true
},
syntax: {
    type: String,
    autoValue: function() {
        if (this.isInsert) {
            return ""
        }
    },
    optional: true
},
description: {
    type: String,
    autoValue: function() {
        if (this.isInsert) {
            return ""
        }
    },
    optional: true
},
features: {
    type: String,
    autoValue: function() {
        if (this.isInsert) {
            return ""
        }
    },
    optional: true},
type: {
    type: String,
    autoValue: function() {
        if (this.isInsert) {
            return ""
        }
    },
    optional: true
},
variants: {
    type: Array,
    autoValue: function() {
        if (this.isInsert) {
            return []
        }
    },
},
'variants.$': {type: String}
})

Commands.attachSchema(Commands.schema)

Meteor.methods({
'commands.insert'(command) {
    if (!this.userId) {
        throw new Meteor.Error('not-authorized')
    }

    Commands.insert(command)
}
})

client

 const setNewHandler = this.props.page.animationFinished ?
        this.props.page.editing ?
            textEditorData.length ?
                () => {
                    Meteor.call(
                        'commands.update',
                        textEditorData[0]._id,
                        {
                            designation: 
              this.childComponents[0].editableContentNode.textContent,
                            name: 
              this.childComponents[1].editableContentNode.textContent,
                            syntax: 
              this.childComponents[2].editableContentNode.textContent,
                            type: 
              this.childComponents[3].editableContentNode.textContent,
                            variants: 
  this.childComponents[4].editableContentNode.textContent.split("\n"),
                            description: 
              this.childComponents[5].editableContentNode.textContent,
                            features: 
              this.childComponents[6].editableContentNode.textContent
                        }
                    )
                } :
                null :
            () => {

                Meteor.call('commands.insert', {})
            } :
        null
ZhenyaUsenko
  • 393
  • 4
  • 8

0 Answers0