简体   繁体   English

在javascript中查询dynamodb日期范围

[英]query dynamodb date range in javascript

If my table looks like this 如果我的表看起来像这样

Hash Key is a number like 7 哈希键是一个像7的数字
Range Key is a timestamp like 2017-02-21 17:20:04.010000 Range Key是一个时间戳,如2017-02-21 17:20:04.010000

and then the payload is something like: 然后有效负载是这样的:

{ "new" : { "N" : "903" }, "number" : { "N" : "7" },
  "Timestamp" : { "S" : "2017-02-21 17:20:04.010000" }, "total" : { "N" : "903" }}

I want to query for all instances where 'number' is 7(s) within a given timestamp range. 我想查询给定时间戳范围内'number'为7(s)的所有实例。

what does my params function need to look like? 我的params功能需要看起来像什么? I have looked at some examples online like this one: 我在网上看过一些像这样的例子:

var params = {
    TableName: "Movies",
    KeyConditionExpression: "#yr = :yyyy",
    ExpressionAttributeNames: {
        "#yr": "year"
    },
    ExpressionAttributeValues: {
        ":yyyy":1985
    }
};

but not really following what the expressions are doing. 但并没有真正遵循表达式的作用。 Any help or pointing me towards an example is greatly appreciated. 非常感谢任何帮助或指向我的例子。

You cannot embed literal values in condition expressions today. 您今天无法在条件表达式中嵌入文字值。 That is why you need to define them in ExpressionAttributeValues and use the variable instead. 这就是为什么你需要在ExpressionAttributeValues中定义它们并使用变量。 Again, some attribute names would make document paths in condition expressions be invalid. 同样,某些属性名称会使条件表达式中的文档路径无效。 You use the ExpressionAttributeNames for those cases. 对这些情况使用ExpressionAttributeNames。 year seems to be a valid document path even without using path variables, so maybe you do not need ExpressionAttributeNames in this example. 即使不使用路径变量, year似乎也是一个有效的文档路径,所以在这个例子中你可能不需要ExpressionAttributeNames。

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

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