如何从dynamoDB表中过滤数据?

时间:2019-07-17 09:59:51

标签: javascript node.js amazon-dynamodb

我将数据存储在dynamodb表中,如下图所示:

enter image description here

我想要在这些列(sender_id,receiver_id_1和Receiver_id_2)中包含17个记录。

我有这样的尝试:

    var params = {
        TableName: table,
        ProjectionExpression: "#sender_id, message, #receiver_id_1, #receiver_id_2, send_date, attachment, msg_status",
        FilterExpression: "(#sender_id = :s_id AND #receiver_id_1 = :r_id_1 AND #receiver_id_2 = :r_id_2) OR (#sender_id = :r_id_1 AND #receiver_id_1 = :s_id AND #receiver_id_2 = :r_id_2) OR (#sender_id = :r_id_1 AND #receiver_id_1 = :r_id_2 AND #receiver_id_2 = :s_id) OR (#sender_id = :s_id AND #receiver_id_1 = :r_id_2 AND #receiver_id_2 = :r_id_1) OR (#sender_id = :r_id_2 AND #receiver_id_1 = :s_id AND #receiver_id_2 = :r_id_1) OR (#sender_id = :r_id_2 AND #receiver_id_1 = :r_id_1 AND #receiver_id_2 = :s_id)",
        ExpressionAttributeNames: {
            "#sender_id": "sender_id",
            "#receiver_id_1": "receiver_id_1",
            "#receiver_id_2": "receiver_id_2",
            "#sender_id": "receiver_id_1",
            "#receiver_id_1": "sender_id",
            "#receiver_id_2": "receiver_id_2",
            "#sender_id": "receiver_id_1",
            "#receiver_id_1": "receiver_id_2",
            "#receiver_id_2": "sender_id",
            "#sender_id": "sender_id",
            "#receiver_id_1": "receiver_id_2",
            "#receiver_id_2": "receiver_id_1",
            "#sender_id": "receiver_id_2",
            "#receiver_id_1": "sender_id",
            "#receiver_id_2": "receiver_id_1",
            "#sender_id": "receiver_id_2",
            "#receiver_id_1": "receiver_id_1",
            "#receiver_id_2": "sender_id",
        },
        ExpressionAttributeValues: {
            ":s_id": sender_id,
            ":r_id_1": receiver_id_1,
            ":r_id_2": receiver_id_2,
            ":r_id_1": receiver_id_1,
            ":s_id": sender_id,
            ":r_id_2": receiver_id_2,
            ":r_id_1": receiver_id_1,
            ":r_id_2": receiver_id_2,
            ":s_id": sender_id,
            ":s_id": sender_id,
            ":r_id_2": receiver_id_2,
            ":r_id_1": receiver_id_1,
            ":r_id_2": receiver_id_2,
            ":s_id": sender_id,
            ":r_id_1": receiver_id_1,
            ":r_id_2": receiver_id_2,
            ":r_id_1": receiver_id_1,
            ":s_id": sender_id,
        },
    };
    docClient.scan(params, function(err, data) {
        console.log(data);
        if (err) {
            console.error("readerror Unable to query. Error:", JSON.stringify(err, null, 2));
        } else {
            data.Items.forEach(function(item) {});
            data['receiver_id_1'] = receiver_id_1;
            data['receiver_id_2'] = receiver_id_2;
            io.to(socket_id).emit("read cvt messages", data);
        }
    });

我将sender_id = 17, receiver_id_1 = somevalue and receiver_id_2=somevalue的值作为参数传递给上述代码。

dynamoDB表中有许多可用记录。但是仍然返回空白数据。

有人可以帮我吗?

还有,我们可以打印执行的查询吗?

0 个答案:

没有答案