-1

我在发电机中有一个键,它有两个具有不同范围键的全局二级索引。像这样:

 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)

在构建查询时,我应该如何区分资源中同一 Key 上的两个 GSI?

编辑 - 向架构添加了额外的上下文,将答案移到了答案部分

4

2 回答 2

1

在这种情况下,您不想使用name索引的属性。您想使用实际属性来执行此操作。

例如:

Resource.query('openOrder').eq(id)
.where('serialNumberEnd').lt(5)

我不知道您的整个架构,因此它与您想要做的事情不完全匹配。但这样的事情应该有效。

您还可以查看源代码中的此测试,了解在一个属性上使用多个索引并进行查询的示例。

于 2018-10-30T20:24:16.837 回答
0
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' } 是必需的。

于 2018-11-08T21:21:28.493 回答