question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Schema option `saveUnknown` is not working for an array

See original GitHub issue

Summary:

Setting the Schema option saveUnknown to true works as expected, but using an array does save empty objects into DynamoDB:

           const catSchema = new dynamoose.Schema({
                name:          String,
                something:     Object,
                somethingElse: Object,
            }, {
                saveUnknown: [
                    'something',
                    'somethingElse',
                ],
            });
            const catModel       = dynamoose.model('Cat', catSchema);

            const cat = {
                name:          'Test',
                something:     {
                    hello: 'world',
                },
                somethingElse: {
                    hello:   {
                        world: 'hello!',
                    },
                    anArray: [1, 2, 3, 4],
                }
            };

            await catModel.create(cat);
aws:dynamodb:putItem:request - {
    "Item": {
        "name": {
            "S": "Test"
        },
        "something": {
            "M": {}
        },
        "somethingElse": {
            "M": {}
        }
    },
    "TableName": "Cat",
    "ConditionExpression": "attribute_not_exists(#__hash_key)",
    "ExpressionAttributeNames": {
        "#__hash_key": "name"
    }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MickLcommented, May 12, 2020

So the problem was that saveUnknown only effects the first layer. In my case wildcards * and ** should have been used as stated in the docs.

0reactions
fishcharliecommented, May 17, 2020

@chadlittle Sounds good. Keep in mind, it’s also better to set the schema property as opposed to saveUnknown. That way it’s more clear what is actually being saved. I’d only recommend saveUnknown for cases when you truly don’t know what you are saving or what your schema looks like.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schema - Dynamoose
saveUnknown, array | boolean, false, This setting lets you specify if the schema should allow properties not defined in the schema. If you...
Read more >
Enum inside the Array is not validting in json-schema
I am validating the json with json_schema. Allowed values for ghrBillingCode should be only "I9NOT". expected result should be error as 2nd and ......
Read more >
dynamoose/CHANGELOG.md - UNPKG
168, This version adds some more options to the model and schema options objects. ... Please give feedback on plugins by creating issues...
Read more >
array — Understanding JSON Schema 2020-12 documentation
{"Not": "an array"}. There are two ways in which arrays are generally used in JSON: List validation: a sequence of arbitrary length where...
Read more >
JSON schema to PL/I mapping - IBM
Should the above behavior be undesirable the user can specify MAPPING-OVERRIDES=NO-ARRAY-NAME-INDEXING as input to the utility which disables the addition of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found