简体   繁体   English

如何在NodeJS中使用dynamoDB使用搜索条件来获取数据并进行限制?

[英]How to get data using search criteria with limit using dynamoDB in NodeJS?

I want apply a bootstrap table for listing with pagination sorting and filtering, pagination is done but when i go for the filtering at that time the data found from only limited data which limit define on LIMIT, so how to apply pagination sorting and filtering Query on Dynamodb just like MySql (limit,offset). 我想应用一个引导表来列出分页排序和过滤功能,分页操作已经完成,但是当我当时进行过滤时,仅从限定在LIMIT上的有限数据中找到的数据,因此如何应用分页排序和过滤查询Dynamodb就像MySql(limit,offset)。

current Query :- 当前查询:

var params = {
                TableName: tableName,
                KeyConditionExpression: (req.body.search.length == 0) ? null : " #emailid = :search_Query",
                FilterExpression  : (req.body.search.length == 0) ? null :  " contains  (#name , :search_Query) OR  contains (#lastName , :search_Query) ",
                ExpressionAttributeNames: (req.body.search.length == 0) ? null : {
                    "#name": "name",
                    "#lastName": "lastName",
                },
                ExpressionAttributeValues: (req.body.search.length == 0) ? null :  {
                    ":search_Query" : req.body.search
                },
                Limit :  req.body.limit ,
                ExclusiveStartKey: (req.body.offset == 0) ? null : {emailid : req.body.emailid } ,


            };
            var lastData=[];
            docClient.scan(params, function scanUntilDone(err, data) {
            });

current behaviour data fetch from only from defined limit if pass limit 5 and search data from only five data but i need five data from all data just like MySql(limit) database then how can i apply query 当前行为数据仅从定义的限制中获取(如果通过限制5)并且仅从五个数据中搜索数据,但是我需要从所有数据中获取五个数据,就像MySql(limit)数据库一样,那么我该如何应用查询

Thank You is advance 谢谢你提前

You would have to pass the search context to the client in your response. 您必须在响应中将搜索上下文传递给客户端。 The LastEvaluatedKey for the "current" page as well as an offset for how many results on the page you included in the response. “当前”页面的LastEvaluatedKey以及您包含在响应中的页面上多少个结果的偏移量。 The client would have to include the search context in the next request. 客户端必须在下一个请求中包括搜索上下文。 Use a higher limit on the actual DynamoDB requests to avoid paginating on the serverside requests. 对实际的DynamoDB请求使用更高的限制,以避免在服务器端请求上分页。

Example (where the client wants neat pages of 5 or fewer results): 示例(客户想要整洁的页面,结果不超过5个):

API Request 1: Limit=5

DDB Request 1: ExclusiveStartKey=null, Limit=100
DDB Response 1: Results=3, LastEvaluatedStartKey=A
DDB Request 2: ExclusiveStartKey=A, Limit=100
DDB Response 2: Results=77, LastEvaluatedStartKey=B

API Response 1: Results=[<3 results from page 1 + 2 from page 2>], SearchKey={A: 2} // the offset

API Request 2: Limit=5, SearchKey={A: 2}
DDB Request 3: ExclusiveStartKey=A, Limit=100
DDB Response 3: Results=77, LastEvaluatedStartKey=B

API Response 1: Results=[<5 results from page 2, starting at offset 2>], SearchKey={A: 7} // the new offset, same page still

It would probably be a good idea to encode/encrypt/obfuscate the search context in the response to the client. 在对客户端的响应中对搜索上下文进行编码/加密/模糊处理可能是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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