Prasad Kanaparthi
Prasad Kanaparthi

Reputation: 6563

How to filter by elements in an array in dynamoose

I've dynamoose schema like below.

var dynamoose = require('dynamoose');
 
var City = dynamoose.model('City', { id: Number, name: String });

and City names data like 'City1', 'City2',...'City100'

I'm trying to get the cities whose city names are 'City2', 'City8' and i didn't find any solution

i tried like below

Model.scan({ name: { contains: 'City2' } }).exec();

How to add City8 also

Note: name column doesn't have any index

Upvotes: 1

Views: 1048

Answers (2)

Heisenbug
Heisenbug

Reputation: 970

I would create a new index with name as hashkey and use .getBatch function. It takes an array of ids (I believe 50 ids is the size limit).

Upvotes: 0

sohaso
sohaso

Reputation: 135

I see that you are using scan. I would use query as it's more performant and more.

The query can be something like:

CitiesModel.query("name").eq("City01").or().where("name").eq("City10").exec()

Regards!

Upvotes: 2

Related Questions