Amazon dynamodb Dynamoose-如何在同一个键上查询两个GSI?
我在dynamo中有一个键,它有两个具有不同范围键的全局二级索引。像这样:Amazon dynamodb Dynamoose-如何在同一个键上查询两个GSI?,amazon-dynamodb,dynamoose,Amazon Dynamodb,Dynamoose,我在dynamo中有一个键,它有两个具有不同范围键的全局二级索引。像这样: const productSchema = new Schema( { productCategory: { type: String, index: [{ global: true, rangeKey: 'serialNumberEnd', name: 'productCategory', throughput: { r
const productSchema = new Schema(
{
productCategory: {
type: String,
index: [{
global: true,
rangeKey: 'serialNumberEnd',
name: 'productCategory',
throughput: { read: 1, write: 1 },
project: ['quantity'],
},
{
global: true,
rangeKey: 'orderType',
name: 'openOrders',
throughput: { read: 1, write: 1 },
project: true,
}],
},
{
throughput: { read: 1, write: 1 },
useNativeBooleans: true,
saveUnknown: true,
},
);`
尝试使用“名称”似乎不是答案
Resource.query('openOrder').eq(id)
在构造查询时,如何区分资源中同一个键上的两个GSI
编辑-将附加上下文添加到架构,将答案移动到答案部分在这种情况下,您不希望使用索引的
名称
属性。您希望使用实际属性来执行此操作
例如:
Resource.query('openOrder').eq(id)
.where('serialNumberEnd').lt(5)
我不知道你的整个模式,所以它与你想要做的不完全匹配。但这样做应该行得通
您还可以查看在一个属性上使用多个索引并进行查询的示例
const result = await Product.query(
{
hash: { productCategory: { eq: 'tags' } },
range: { orderType: { eq: 'sale' } },
},
{ indexName: 'openOrders' },).exec();
我理解这个语法有点慢。希望这对其他人有帮助
编辑:语法稍微清晰一点/架构的上下文更多
const result = await Product.query('productCategory', { indexName: 'openOrders' }).eq('tags')
.where('orderType').eq('purchase')
.exec();
我没有运气让Dynamoose根据在“where”语句中找到的范围来识别正确的索引。需要{indexName:'value'}。query()函数只需要一个参数