Dynamoose - How to Query Two GSI on the same Key?
I have a key in dynamo that has two Global Secondary Indexes with different range keys. Like this:
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,
,
);`
Trying to use the 'name' does not seem to be the answer.
Resource.query('openOrder').eq(id)
How am I supposed to distinguish between the two GSI's on the same Key in a resource when constructing a query?
EDIT - Added additional context to the schema, moved answer to the answer section
amazon-dynamodb dynamoose
add a comment |
I have a key in dynamo that has two Global Secondary Indexes with different range keys. Like this:
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,
,
);`
Trying to use the 'name' does not seem to be the answer.
Resource.query('openOrder').eq(id)
How am I supposed to distinguish between the two GSI's on the same Key in a resource when constructing a query?
EDIT - Added additional context to the schema, moved answer to the answer section
amazon-dynamodb dynamoose
add a comment |
I have a key in dynamo that has two Global Secondary Indexes with different range keys. Like this:
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,
,
);`
Trying to use the 'name' does not seem to be the answer.
Resource.query('openOrder').eq(id)
How am I supposed to distinguish between the two GSI's on the same Key in a resource when constructing a query?
EDIT - Added additional context to the schema, moved answer to the answer section
amazon-dynamodb dynamoose
I have a key in dynamo that has two Global Secondary Indexes with different range keys. Like this:
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,
,
);`
Trying to use the 'name' does not seem to be the answer.
Resource.query('openOrder').eq(id)
How am I supposed to distinguish between the two GSI's on the same Key in a resource when constructing a query?
EDIT - Added additional context to the schema, moved answer to the answer section
amazon-dynamodb dynamoose
amazon-dynamodb dynamoose
edited Nov 8 '18 at 21:22
asked Oct 29 '18 at 22:46
Bryce
13
13
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
In this case you don't want to be using the name property of the index. You want to be using the actual property to do this.
For example:
Resource.query('openOrder').eq(id)
.where('serialNumberEnd').lt(5)
I don't know your entire schema so it's not an exact match of what you want to do. But something like that should work.
You can also look at this test in the source code for an example of using multiple indexes on one property and querying.
add a comment |
const result = await Product.query(
hash: productCategory: eq: 'tags' ,
range: orderType: eq: 'sale' ,
,
indexName: 'openOrders' ,).exec();
I was a bit slow at getting to this syntax. Hope this helps someone else.
EDIT: A little cleaner syntax/more context to the schema
const result = await Product.query('productCategory', indexName: 'openOrders' ).eq('tags')
.where('orderType').eq('purchase')
.exec();
I had no luck getting Dynamoose to recognize the correct index based on the Range found in a 'where' statement. The indexName: 'value' is needed.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53055008%2fdynamoose-how-to-query-two-gsi-on-the-same-key%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In this case you don't want to be using the name property of the index. You want to be using the actual property to do this.
For example:
Resource.query('openOrder').eq(id)
.where('serialNumberEnd').lt(5)
I don't know your entire schema so it's not an exact match of what you want to do. But something like that should work.
You can also look at this test in the source code for an example of using multiple indexes on one property and querying.
add a comment |
In this case you don't want to be using the name property of the index. You want to be using the actual property to do this.
For example:
Resource.query('openOrder').eq(id)
.where('serialNumberEnd').lt(5)
I don't know your entire schema so it's not an exact match of what you want to do. But something like that should work.
You can also look at this test in the source code for an example of using multiple indexes on one property and querying.
add a comment |
In this case you don't want to be using the name property of the index. You want to be using the actual property to do this.
For example:
Resource.query('openOrder').eq(id)
.where('serialNumberEnd').lt(5)
I don't know your entire schema so it's not an exact match of what you want to do. But something like that should work.
You can also look at this test in the source code for an example of using multiple indexes on one property and querying.
In this case you don't want to be using the name property of the index. You want to be using the actual property to do this.
For example:
Resource.query('openOrder').eq(id)
.where('serialNumberEnd').lt(5)
I don't know your entire schema so it's not an exact match of what you want to do. But something like that should work.
You can also look at this test in the source code for an example of using multiple indexes on one property and querying.
answered Oct 30 '18 at 20:24
Charlie Fish
5,43942971
5,43942971
add a comment |
add a comment |
const result = await Product.query(
hash: productCategory: eq: 'tags' ,
range: orderType: eq: 'sale' ,
,
indexName: 'openOrders' ,).exec();
I was a bit slow at getting to this syntax. Hope this helps someone else.
EDIT: A little cleaner syntax/more context to the schema
const result = await Product.query('productCategory', indexName: 'openOrders' ).eq('tags')
.where('orderType').eq('purchase')
.exec();
I had no luck getting Dynamoose to recognize the correct index based on the Range found in a 'where' statement. The indexName: 'value' is needed.
add a comment |
const result = await Product.query(
hash: productCategory: eq: 'tags' ,
range: orderType: eq: 'sale' ,
,
indexName: 'openOrders' ,).exec();
I was a bit slow at getting to this syntax. Hope this helps someone else.
EDIT: A little cleaner syntax/more context to the schema
const result = await Product.query('productCategory', indexName: 'openOrders' ).eq('tags')
.where('orderType').eq('purchase')
.exec();
I had no luck getting Dynamoose to recognize the correct index based on the Range found in a 'where' statement. The indexName: 'value' is needed.
add a comment |
const result = await Product.query(
hash: productCategory: eq: 'tags' ,
range: orderType: eq: 'sale' ,
,
indexName: 'openOrders' ,).exec();
I was a bit slow at getting to this syntax. Hope this helps someone else.
EDIT: A little cleaner syntax/more context to the schema
const result = await Product.query('productCategory', indexName: 'openOrders' ).eq('tags')
.where('orderType').eq('purchase')
.exec();
I had no luck getting Dynamoose to recognize the correct index based on the Range found in a 'where' statement. The indexName: 'value' is needed.
const result = await Product.query(
hash: productCategory: eq: 'tags' ,
range: orderType: eq: 'sale' ,
,
indexName: 'openOrders' ,).exec();
I was a bit slow at getting to this syntax. Hope this helps someone else.
EDIT: A little cleaner syntax/more context to the schema
const result = await Product.query('productCategory', indexName: 'openOrders' ).eq('tags')
.where('orderType').eq('purchase')
.exec();
I had no luck getting Dynamoose to recognize the correct index based on the Range found in a 'where' statement. The indexName: 'value' is needed.
edited Nov 12 '18 at 21:00
Charlie Fish
5,43942971
5,43942971
answered Nov 8 '18 at 21:21
Bryce
13
13
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53055008%2fdynamoose-how-to-query-two-gsi-on-the-same-key%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown