简体   繁体   中英

scan or query data by deleted column

I have a boolean "deleted" column in my database and I'm trying to scan all records that are not deleted (it's a soft delete)

      var scanParams = {
        TableName: "students",
        FilterExpression: "deleted = :deleted",
        ExpressionAttributeValues: {
          ":deleted": false,
        },
      };

      const scan = await db.scan(scanParams).promise();

this does not return any data because I'm not storing my records with deleted = false. I only add deleted = true when the records are deleted.

在此处输入图片说明

I tried with

        ExpressionAttributeValues: {
          ":deleted": "",
        },

but now I get no records at all. thank you.

Try to reverse your scan condition - Get items that have delete is NOT true.

 var scanParams = {
        TableName: "students",
        FilterExpression: "deleted <> :deleted", // NOT EQUAL TRUE -> empty or false
        ExpressionAttributeValues: {
          ":deleted": true,
        },
      };

      const scan = await db.scan(scanParams).promise();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM