clarkie / dynogels

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

Unable to query using only the rangeKey. #137

Closed shishiranshuman closed 6 years ago

shishiranshuman commented 6 years ago

I just started working on DynamoDB so please forgive me if the following seems silly.

Now what I want is to get the list of records by rangeKey. I don't want to use the scan operation since it impacts the performance. I am unable to achieve this with the query operation. Trying to achieve something like this with dynogels.

Any kind of help would be really helpful to me.

Thanks.

Dynogels: 9.0.0 Node: 6.10.3

cdhowie commented 6 years ago

You cannot query on only the range key. Does your global secondary index use your table's range key as its hash key? Showing your model would be helpful.

shishiranshuman commented 6 years ago

Sure. Here is the model I am using:

dynogels.define('user-address', {
    hashKey : 'user_id',
    rangeKey: 'location',

    timestamps : true,

    schema : {
        location: Joi.string(),
        pin: Joi.number(),
        user_id: Joi.string()
    },

    indexes: [{
        hashKey: 'user_id',
        rangeKey: 'location',
        name: 'AddressGlobalIndex',
        type: 'global',
    }],
});

After reading your comment, I think I understand what I am doing wrong. Will let you know

cdhowie commented 6 years ago

Your index has the same hash key and range key as your table. This is entirely redundant.

shishiranshuman commented 6 years ago

Yes, you are right. Fixed it. It was a dumb mistake. Thanx a lot for the help. ✌️