簡體   English   中英

在值為 Set 的屬性上創建 GSI

[英]Create GSI on an attribute which has the value of Set

所以我想創建一個簡單的 Dynamodb 表,稱為提醒,目前有 3 列:

  1. reminder_id :這是 hash 密鑰
  2. reminder_tag :我想在這個字段上有一個全局二級索引。 但同時我想確保標簽屬性應該具有 Set 的數據類型。 因為提醒上可以有多個標簽。
  3. reminder_title :我也想在這個字段上有一個全局二級索引。 這將是一個字符串字段。

我檢查了文檔: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/customizations/dynamodb.html#valid-dynamodb-types ,了解 Boto3 中可用的可能數據類型。

所以我想出了這個腳本:

import boto3


def create_reminders_table():
    """Just create the reminders table."""
    session = boto3.session.Session(profile_name='dynamo_local')
    dynamodb = session.resource('dynamodb', endpoint_url="http://localhost:8000")
    table = dynamodb.create_table(
        TableName='Reminders',
        KeySchema=[
            {
                'AttributeName': 'reminder_id',
                'KeyType': 'HASH'
            }
        ],
        AttributeDefinitions=[
            {
                'AttributeName': 'reminder_id',
                'AttributeType': 'S'
            },
            {
                'AttributeName': 'reminder_tag',
                'AttributeType': 'SS'
            },
            {
                'AttributeName': 'reminder_title',
                'AttributeType': 'S'
            }
        ],
        GlobalSecondaryIndexes=[
            {
                'IndexName': 'ReminderTagGsi',
                'KeySchema': [
                    {
                        'AttributeName': 'reminder_tag',
                        'KeyType': 'HASH'
                    }
                ],
                'Projection': {
                    'ProjectionType': 'INCLUDE',
                    'NonKeyAttributes': [
                        'reminder_title'
                    ]
                }
            },
            {
                'IndexName': 'ReminderTitleGsi',
                'KeySchema': [
                    {
                        'AttributeName': 'reminder_title',
                        'KeyType': 'HASH'
                    }
                ],
                'Projection': {
                    'ProjectionType': 'KEYS_ONLY'
                }
            }
        ],
        BillingMode='PAY_PER_REQUEST'
    )
    return table


if __name__ == '__main__':
    movie_table = create_reminders_table()
    print("Table status:", movie_table.table_status)

但是當我運行它時,我遇到了以下問題:

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the CreateTable operation: Member must satisfy enum value set: [B, N, S]

我搜索並遇到了有相同問題的人提出的這個問題: https://forums.aws.amazon.com/thread.jspa?messageID=613970

有人可以幫我解決這個問題,因為不提供數據類型的解決方案也不起作用。

也可以在具有 Set 值的屬性上建立索引嗎? 我的意思是我應該讓用戶能夠搜索帶有標簽的提醒,為此我需要一套。

請有人幫助我解決這個問題。

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html

“每個主鍵屬性必須是一個標量(意味着它只能包含一個值)。 主鍵屬性允許的唯一數據類型是字符串、數字或二進制。 對於其他非關鍵屬性則沒有此類限制。”

是否可以在值為 Set 的屬性上建立索引?

不,正如CreateTable文檔所說,“KeySchema 中的屬性也必須在 AttributeDefinitions 中定義”,數據類型為 (S)tring、(N)umber 或 (B)inary。

使用戶能夠搜索帶有標簽的提醒,為此我需要一套。

一對多關系的 DynamoDB 解決方法是復合排序鍵,如urgent#work 不過,這只適用於少量固定數量的標簽。

您最不壞的選擇是按用戶查詢(並可能使用某些排序鍵進一步縮小范圍),然后按 DynamoDB 外部的標簽成員資格過濾結果。 (注意IN運算符不能在查詢的FilterConditionExpression中使用,因此它在這里對您沒有用)。

我想在reminder_title上有一個全局二級索引

reminder_title不適合作為索引主鍵。 索引(和表)的Primary Key必須確保每條記錄的唯一性。 標題可能不會。 您可能需要 3 個元素的組合,即user_idrequest_idtitle ,以確保跨記錄的鍵唯一性。

考慮一個復合主鍵,例如, Partition Keyuser_id (= HASH ) 和連接title#request_id的新列 ( SK ) 中的復合排序鍵 然后,您將按用戶按標題搜索:

user_id="Zaphod" AND begins_with(SK, "exercise")

Firebase 功能:無法設置 # 的屬性配置<object>只有一個吸氣劑<div id="text_translate"><p> Firebase 功能運行良好我更新到最新的 firebase-tools 現在運行 firebase 服務時遇到此錯誤問題。</p><pre> [debug] [2020-05-28T20:37:11.387Z] [runtime-status] [93658] Error in handleMessage: => TypeError: Cannot set property config of #<Object> which has only a getter: TypeError: Cannot set property config of #<Object> which has only a getter at {....}/node/v10.15.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:455:19 at Generator.next (<anonymous>) at fulfilled ({....}/node/v10.15.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:5:58) [warn] ⚠ functions: Cannot set property config of #<Object> which has only a getter {"metadata":{"emulator":{"name":"functions"},"message":"Cannot set property config of #<Object> which has only a getter"}} [warn] ⚠ Your function was killed because it raised an unhandled error. {"metadata":{"emulator":{"name":"functions"},"message":"Your function was killed because it raised an unhandled error."}}</pre></div></object>

[英]Firebase functions : Cannot set property config of #<Object> which has only a getter

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 我們可以將列表類型屬性定義為 GSI 中的 hash 鍵嗎 DynamoDB GSI BatchGetItem Firebase 功能:無法設置 # 的屬性配置<object>只有一個吸氣劑<div id="text_translate"><p> Firebase 功能運行良好我更新到最新的 firebase-tools 現在運行 firebase 服務時遇到此錯誤問題。</p><pre> [debug] [2020-05-28T20:37:11.387Z] [runtime-status] [93658] Error in handleMessage: => TypeError: Cannot set property config of #<Object> which has only a getter: TypeError: Cannot set property config of #<Object> which has only a getter at {....}/node/v10.15.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:455:19 at Generator.next (<anonymous>) at fulfilled ({....}/node/v10.15.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:5:58) [warn] ⚠ functions: Cannot set property config of #<Object> which has only a getter {"metadata":{"emulator":{"name":"functions"},"message":"Cannot set property config of #<Object> which has only a getter"}} [warn] ⚠ Your function was killed because it raised an unhandled error. {"metadata":{"emulator":{"name":"functions"},"message":"Your function was killed because it raised an unhandled error."}}</pre></div></object> 更新 DynamoDB 的 GSI,舊數據不會在新 GSI 中更新 GSI 上的 DynamoDB gt() 查詢 DynamoDB - GSI 與復制 Dynamodb GSI 包含 boolean 調用 RDS 數據服務 executeStatement 拋出“參數 X 具有未設置字段的值” TestWebACL 錯誤原因:您的語句為一個只需要一個值的字段設置了多個值 無法使用 DynamoDB GSI
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM