• <tfoot id='w24vs'></tfoot>
      <bdo id='w24vs'></bdo><ul id='w24vs'></ul>

    <small id='w24vs'></small><noframes id='w24vs'>

        <legend id='w24vs'><style id='w24vs'><dir id='w24vs'><q id='w24vs'></q></dir></style></legend>
      1. <i id='w24vs'><tr id='w24vs'><dt id='w24vs'><q id='w24vs'><span id='w24vs'><b id='w24vs'><form id='w24vs'><ins id='w24vs'></ins><ul id='w24vs'></ul><sub id='w24vs'></sub></form><legend id='w24vs'></legend><bdo id='w24vs'><pre id='w24vs'><center id='w24vs'></center></pre></bdo></b><th id='w24vs'></th></span></q></dt></tr></i><div id='w24vs'><tfoot id='w24vs'></tfoot><dl id='w24vs'><fieldset id='w24vs'></fieldset></dl></div>

        在非关键属性上查询 DynamoDB

        时间:2023-08-29
      2. <i id='MtBkQ'><tr id='MtBkQ'><dt id='MtBkQ'><q id='MtBkQ'><span id='MtBkQ'><b id='MtBkQ'><form id='MtBkQ'><ins id='MtBkQ'></ins><ul id='MtBkQ'></ul><sub id='MtBkQ'></sub></form><legend id='MtBkQ'></legend><bdo id='MtBkQ'><pre id='MtBkQ'><center id='MtBkQ'></center></pre></bdo></b><th id='MtBkQ'></th></span></q></dt></tr></i><div id='MtBkQ'><tfoot id='MtBkQ'></tfoot><dl id='MtBkQ'><fieldset id='MtBkQ'></fieldset></dl></div>

          <tbody id='MtBkQ'></tbody>
        <legend id='MtBkQ'><style id='MtBkQ'><dir id='MtBkQ'><q id='MtBkQ'></q></dir></style></legend>
          <bdo id='MtBkQ'></bdo><ul id='MtBkQ'></ul>
          <tfoot id='MtBkQ'></tfoot>

              • <small id='MtBkQ'></small><noframes id='MtBkQ'>

                  本文介绍了在非关键属性上查询 DynamoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  是否可以在 AWS 版本 2 中使用非关键属性过滤 DynamoDB 查询?亚马逊表示他们可以做到:http://amzn.to/1FVgQ9B.但是他们也提供 API 吗?我找到了 AWSDynamoDBQueryExpression,但我认为它只允许过滤范围键(没有足够的文档).我正在 iOS 和 AWS 版本 2 中寻找合适的 API.谢谢!

                  Is it possible to filter DynamoDB queries using non-key attributes in AWS version 2 ? Amazon says that they can do it: http://amzn.to/1FVgQ9B. But do they also give the API? I found AWSDynamoDBQueryExpression, but I think it only lets filtering on the range key (not enough documentation). I'm looking for the proper API in iOS and AWS version 2. Thanks!

                  推荐答案

                  我正在回答我自己的问题.这也是我在 AWS 支持论坛上发布的内容:

                  I'm answering my own question. This is what I posted on AWS support forum as well:

                  您无法使用高级 API -- AWSDynamoDBObjectMapper 来执行此操作.使用 AWSDynamoDBObjectMapper 时,需要向查询方法提供一个 AWSDynamoDBQueryExpression 对象来指定查询条件.AWSDynamoDBQueryExpression 没有为您提供在非关键属性上设置过滤器(条件)的选项.我想知道为什么不支持这个!但是,AWSDynamoDBScanExpression 允许您在使用扫描方法时指定非关键属性的条件.但是,当您真正的意思是查询时,您不想扫描.

                  You can't do this with the high level API -- AWSDynamoDBObjectMapper. When using AWSDynamoDBObjectMapper, you need to provide an AWSDynamoDBQueryExpression object to the query method to specify the query conditions. AWSDynamoDBQueryExpression doesn't give you the option to set filters(conditions) on non-key attributes. I wonder why this isn't supported! However, AWSDynamoDBScanExpression lets you specify conditions on non-key attributes when you use the scan method. But you don't want to scan when you actually mean a query.

                  幸运的是,您可以使用低级别 API 执行此操作,方法是直接在 AWSDynamoDB 上调用查询,提供 AWSDynamoDBQueryInput,让您可以指定许多低级别参数.AWSDynamoDBQueryInput 允许您使用 queryFilter 或 filterExpression 指定非键属性的过滤条件.不推荐使用 queryFilter,建议使用 filterExpression.以下是帮助我解决这个问题的两个文件:

                  Fortunately, you can do this using the low level API by directly calling query on AWSDynamoDB providing an AWSDynamoDBQueryInput which lets you specify a lot of low level parameters. AWSDynamoDBQueryInput lets you specify the filter conditions on non-key attributes using either queryFilter or filterExpression. queryFilter is deprecated, it's recommended to use filterExpression. Here are the two documents that helped me to figure this out:

                  http://docs.aws.amazon.com/amazondynamodb/最新/APIReference/API_Query.htmlhttp://docs.aws.amazon.com/AWSiOSSDK/latest/Classes/AWSDynamoDBQueryInput.html

                  这是 swift 中的代码示例.在此代码中,我基于作为非关键属性的已批准"字段进行过滤.recId 为主键:

                  Here's a code example in swift. In this code I'm filtering based on "approved" field that is a non-key attribute. recId is the primary key:

                      func getApprovedRecords(recId: Int) {
                  
                  
                  
                       let dynamoDB = AWSDynamoDB.defaultDynamoDB()
                  
                          var startKey = nil
                  
                          var queryInput = AWSDynamoDBQueryInput()
                  
                          queryInput.tableName = TABLE_NAME
                  
                          queryInput.limit = QUERY_SIZE
                  
                          queryInput.exclusiveStartKey = startKey
                  
                  
                  
                          var recIdValue = AWSDynamoDBAttributeValue()
                  
                          recIdValue.N = String(recId)
                  
                          var recIdCondition = AWSDynamoDBCondition()
                  
                          recIdCondition.comparisonOperator = AWSDynamoDBComparisonOperator.EQ
                  
                          recIdCondition.attributeValueList = [recIdValue]
                  
                  
                  
                          queryInput.keyConditions = [ "recId"" : recIdCondition]
                  
                  
                          var oneValue = AWSDynamoDBAttributeValue()
                  
                          oneValue.N = "1"
                  
                  
                  
                          queryInput.expressionAttributeValues = [ ":one" : oneValue ]    
                  
                          queryInput.filterExpression = "approved = :one"
                  
                          dynamoDB.query(queryInput).continueWithBlock { (task: BFTask!) -> AnyObject! in
                  
                              if ((task.error) != nil) {
                  
                                  NSLog("The request failed. Error: (task.error)")
                  
                              }
                  
                              if ((task.exception) != nil) {
                  
                                  NSLog("The request failed. Exception: (task.exception)")
                  
                              }
                  
                              if ((task.result) != nil) {
                  
                                  NSLog("The request  succeeded.")
                  
                                  let results = task.result as! AWSDynamoDBQueryOutput
                  
                                  for r in results.items {
                  
                                      // do whatever with the result
                  
                                  }
                  
                              }
                  
                              return nil
                  
                          }
                  
                      }
                  

                  这篇关于在非关键属性上查询 DynamoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:DynamoDB 自动递增 ID &amp;服务器时间(iOS SDK) 下一篇:AWS DynamoDB 批量获取请求 - iOS

                  相关文章

                  最新文章

                  <i id='hpdmt'><tr id='hpdmt'><dt id='hpdmt'><q id='hpdmt'><span id='hpdmt'><b id='hpdmt'><form id='hpdmt'><ins id='hpdmt'></ins><ul id='hpdmt'></ul><sub id='hpdmt'></sub></form><legend id='hpdmt'></legend><bdo id='hpdmt'><pre id='hpdmt'><center id='hpdmt'></center></pre></bdo></b><th id='hpdmt'></th></span></q></dt></tr></i><div id='hpdmt'><tfoot id='hpdmt'></tfoot><dl id='hpdmt'><fieldset id='hpdmt'></fieldset></dl></div>

                    1. <legend id='hpdmt'><style id='hpdmt'><dir id='hpdmt'><q id='hpdmt'></q></dir></style></legend>
                        <bdo id='hpdmt'></bdo><ul id='hpdmt'></ul>
                      <tfoot id='hpdmt'></tfoot>

                      <small id='hpdmt'></small><noframes id='hpdmt'>