SailsJS conf.bootstrap 无法插入初始数据

SailsJS conf.bootstrap fails to insert initial data

我正在尝试从 bootstrap conf 将初始数据加载到 sails 应用程序 (sails v1.0.2) 中,但失败并显示错误:

error: UsageError: Invalid initial data for new record.
Details:
  Missing value for required attribute `agentType`.  Expected a string, but instead, got: undefined

型号:

module.exports = {
  attributes: {
    agentType: {
      type: 'string',
      required: true
    },
    amount: {
      type: 'number',
      defaultsTo: 0
    },
    application: {
      model: 'application'
    }
  },
};

我的 bootstrap 文件:

const agents = [
  {
    agentType: 'Java App Agent',
    amount: 30
  }, {
    agentType: '.NET App Agent',
    amount: 18
  }, {
    agentType: '.NET Machine Agent',
    amount: 33
  }, {
    agentType: 'Standalone Machine Agent',
    amount: 46
  }];

    module.exports.bootstrap = function(done) {
      agents.forEach(agent => {
        Agent.findOrCreate({
            agentType: agent.agentType,
            amount: agent.amount
          })
          .exec((error, agent) => {
            if (error) sails.log.error(error);
            sails.log.info('Created fixture agent', agent)
          })
      });
      done()
    };

我正在使用 "sails lift --drop" 命令启动 sails 应用程序。

请指教我做错了什么。

提前致谢!

正如来自 Glitter 的@texh 所指出的:

https://sailsjs.com/documentation/reference/waterline-orm/models/find-or-create

 module.exports.bootstrap = function(done) {
  agents.forEach(agent => {
    Agent.findOrCreate(agent, agent)
      .exec((error, agent) => {
        if (error) sails.log.error(error);
        sails.log.info('Created fixture agent', agent)
      })
  });
  done()
};

You have to pass the search criteria and the inital values to set if a record isn't found