How do you query for a non-existent (null) attribute in DynamoDB

后端 未结 2 1635
情话喂你
情话喂你 2020-12-16 09:04

I\'m trying to query a DynamoDB table to find all items where the email attribute is not set. A global secondary index called EmailPasswordIndex ex

2条回答
  •  情歌与酒
    2020-12-16 09:55

    @jaredHatfield is correct if the field does not exist but that will not work if the filed is null. NULL is a keyword and can't used directly. But you can use it with ExpressionAttributeValues.

    const params = {
        TableName: "Accounts",
        FilterExpression: "attribute_not_exists(email) or email = :null",
        ExpressionAttributeValues: {
            ':null': null
        }
    }
    
    dynamodb.scan(params, (err, data) => {
        if (err)
            console.log(JSON.stringify(err, null, 2));
        else
            console.log(JSON.stringify(data, null, 2));
    })
    

提交回复
热议问题