1. <tfoot id='QYt4L'></tfoot>

      <legend id='QYt4L'><style id='QYt4L'><dir id='QYt4L'><q id='QYt4L'></q></dir></style></legend>
      • <bdo id='QYt4L'></bdo><ul id='QYt4L'></ul>

    2. <small id='QYt4L'></small><noframes id='QYt4L'>

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

      如何使用“包含"进行搜索?使用 DynamoDB

      时间:2023-09-03

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

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

          <legend id='AQQkJ'><style id='AQQkJ'><dir id='AQQkJ'><q id='AQQkJ'></q></dir></style></legend>

                  <tbody id='AQQkJ'></tbody>

                本文介绍了如何使用“包含"进行搜索?使用 DynamoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试在我的 React 应用上创建搜索功能.

                I'm trying to make search function on my React app.

                我有这张 DynamoDB 表:

                I have this DynamoDB table:

                ---------------------
                movie_id | movie_name
                ---------------------
                1        | name a
                ---------------------
                2        | name b
                ---------------------
                

                我想创建一个搜索功能,在 React 应用的搜索输入中搜索b",并从数据库中获取name b"作为结果.

                I want to make a search function to search "b" on the React app's search input and get "name b" from the DB as the result.

                我尝试使用 CONTAINS 进行 query,但没有奏效,而且似乎不是正确的方法.

                I tried to query with CONTAINS but didn't work and does not seem to be a proper way to do it.

                const SEARCH_KEYWORD = "b";
                
                let params = {
                   TableName : 'TABLE_NAME',
                   KeyConditionExpression: "contains(#movie_name, :movie_name)",
                   ExpressionAttributeNames:{
                     "#movie_name": 'movie_name'
                   },
                   ExpressionAttributeValues:{
                       ":movie_name": SEARCH_KEYWORD
                   }
                };
                documentClient.query(params, function(err, data) {
                  console.log(data);
                });
                

                使用 DynamoDB 在我的 React 应用程序上创建搜索功能的最佳方法是什么?

                What is the best way to create search function on my React app with DynamoDB?

                通过搜索关键字运行查询以检查数据是否包含关键字值是否有意义?

                Does it even make sense to run a query by the search keyword to check if the data contains keyword value?

                推荐答案

                CONTAINS 运算符在 query API 中不可用.您需要为此使用 scan API(查看此链接).

                The CONTAINS operator is not available in the query API. You need to use the scan API for this (see this link).

                尝试以下方法:

                const AWS = require('aws-sdk');
                const documentClient = new AWS.DynamoDB.DocumentClient();
                const SEARCH_KEYWORD = "b";
                
                let params = {
                    TableName : 'TABLE_NAME',
                    FilterExpression: "contains(#movie_name, :movie_name)",
                    ExpressionAttributeNames: {
                        "#movie_name": "movie_name",
                    },
                    ExpressionAttributeValues: {
                        ":movie_name": SEARCH_KEYWORD,
                    }       
                };
                
                documentClient.scan(params, function(err, data) {
                    console.log(data);
                });
                

                结果:

                { 
                    Items: [ 
                        { 
                            movie_id: 2,
                            movie_name: 'name b' 
                        } 
                    ], 
                    Count: 1, 
                    ScannedCount: 2 
                }
                

                这篇关于如何使用“包含"进行搜索?使用 DynamoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 Amazon Dynamo DB 进行不区分大小写的查询 下一篇:在哪里可以找到 AWS-SDK for dynamodb 在 NodeJS 打字稿

                相关文章

                最新文章

                  • <bdo id='mqbJX'></bdo><ul id='mqbJX'></ul>
                  <legend id='mqbJX'><style id='mqbJX'><dir id='mqbJX'><q id='mqbJX'></q></dir></style></legend>

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

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

                    <tfoot id='mqbJX'></tfoot>