Kushagara.K Kushagara.K - 11 months ago 121
Node.js Question

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

I have a schema in dynamodb as shown below, I am using Joi, Vogels and 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()

I am trying to insert the following data in the table

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

I am using the below nodejs code to insert the data to table

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

I am getting the following error

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

Can someone help me out or explain , why i am getting this error and how to fix it?

Answer Source

The problem is on the UUID field (i.e. attribute 'a'). I understand that vogels is supposed to generate the UUID automatically. However, there is no working example of automatic UUID value generation for non-key attributes though as per the document it should generate. It should work OK if you define a UUID for key attributes.

The below solution is a workaround to generate the UUID and assign the value to attribute 'a'.

1) Install the node-uuid module

node install node-uuid

2) Add the requires:-

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

3) Change the object as mentioned below:-

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

You should be able to insert an item successfully. I have tested it and works ok.