How to fix Joi error on DynamoDB TypeError: child.schema._getLabel is not a function

How to fix Joi error on DynamoDB TypeError: child.schema._getLabel is not a function

我在 dynamodb 中有一个架构,如下所示,我正在使用 Joi、Vogels 和 NodeJS

schema: {
email: Joi.string().email(),
  item: Joi.array().items(Joi.object().keys({
    a: Vogels.types.uuid(),
    b: Joi.string(),
    c: Joi.string(),
    d: Joi.string().email()
 }))

我正在尝试在 table

中插入以下数据

var Obj = {
    email: 'a@b.com',
    item: [{
        b: 'data',
        c: 'some-data',
        d: 'b@c.com'
    }]
};

我正在使用下面的 nodejs 代码将数据插入 table

Model.create(Obj, function(err, data) {
    if (err){
        console.log(err);
        return cb(err);
    } else {
    console.log(data);
    return cb(null,data);
    }
});

我收到以下错误

errors.push(this.createError('object.child', { key, child: child.schema._getLabel(key), reason: result.errors }, localState, options));

TypeError: child.schema._getLabel is not a function

有人可以帮我解决或解释为什么我会收到此错误以及如何解决它吗?

问题出在 UUID 字段上(即属性 'a')。我知道 vogels 应该自动生成 UUID。但是,尽管根据它应该生成的文档,但没有为非键属性自动生成 UUID 值的工作示例。如果您为关键属性定义一个 UUID,它应该可以正常工作。

以下解决方案是生成 UUID 并将值分配给属性 'a' 的解决方法。

1) 安装node-uuid模块

node install node-uuid

2) 添加要求:-

var nodeUUID = require('node-uuid');

3) 改变对象如下:-

var Obj = {
    email : 'abc@b.com',
    item : [ {
        a : nodeUUID.v1(),
        b : 'data',
        c : 'some-data',
        d : 'b@c.com'
    } ]
};

您应该能够成功插入项目。我已经测试过了,工作正常。