clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
490 stars 110 forks source link

Missing some key conditions #17

Closed cdhowie closed 8 years ago

cdhowie commented 8 years ago

Here we can see the list of supported key conditions in dynogels. There are more conditions supported by DynamoDB itself: 'EQ | NE | IN | LE | LT | GE | GT | BETWEEN | NOT_NULL | NULL | CONTAINS | NOT_CONTAINS | BEGINS_WITH'. In this particular case, I need the IN operator.

However, this may be more troublesome as I'm not sure if the query() function will work without an argument. In my case, I have a set of values and I want to get all records where the hash key is equal to one of those values. It doesn't appear that dynogels supports this, which means I would have to use scan() instead.

clarkie commented 8 years ago

You can use dynogels as stated to query keys that are in a list:

Account.getItems(['foo@example.com','bar@example.com', 'test@example.com'], function (err, accounts) {
  console.log('loaded ' + accounts.length + ' accounts'); // prints loaded 3 accounts
});

https://github.com/clarkie/dynogels#batch-get-items

@cdhowie can you point me to the docs that show the list of key conditions supported by dynamoDB as I'm not convinced they do. Their own gui only supports the ones supported by dynogels and even then it's only on range keys:

image

cdhowie commented 8 years ago

Sorry, I left out a key detail here: I'm trying to do exactly what you show in your example code (I know about this feature and use it elsewhere) but in this case I'm trying to do this with a GSI. I can see how I'd do that using the document client API, but I can't find a way to do it with dynogels.

clarkie commented 8 years ago

Could you post a link to the docs? Thanks

cdhowie commented 8 years ago

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#query-property

Note KeyConditions..ComparisonOperator.

cdhowie commented 8 years ago

So to clarify, what I want to do is query with an IN condition against the hash key of a GSI.

clarkie commented 8 years ago

Great, thanks. Could you post the code you've got using the aws-sdk? Thanks

cdhowie commented 8 years ago

So this seems to be a case where the documentation for DocumentClient is incorrect. Unfortunately, DynamoDB doesn't even support batch get operations on GSIs. The only apparent way to get all records in a GSI where the hash key is in a set of values is to execute a query operation per value. :(

clarkie commented 8 years ago

Ah ok, thanks for taking the time to let me know.