8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DynamoDBのscanのFilterExpressionでネストしたクエリを使う

Posted at

FilterExpression(条件1) OR ( (条件2) AND (条件3) )の様にネストできる。

var item = 'hoge';
var shipping_state1 = 'shippingA';
var shipping_state2 = 'shippingB';
var params = {
  TableName: 'Item',
  FilterExpression: '(items = :items) AND ((shipping_state=:shipping_state1) OR (shipping_state=:shipping_state2))',
  ExpressionAttributeValues: {
	':items':item,
	':shipping_state1':shipping_state1,
	':shipping_state2':shipping_state2
  }
}
dynamodb.scan(params).promise().then(function(data) {
	console.log(data);
}).catch(function (error) {
	console.log(error)
})

INを使う場合は(キー IN (:候補1,:候補2,:候補3)のようにする。

var item = 'hoge';
var shipping_state1 = 'shippingA';
var shipping_state2 = 'shippingB';
var params = {
  TableName: 'Site',
  FilterExpression: '(items = :items) AND (shipping_state IN (:shipping_state1,:shipping_state2,:shipping_state3))',
  ExpressionAttributeValues: {
	':items':item,
	':shipping_state1':shipping_state1,
	':shipping_state2':shipping_state2
  }
}
dynamodb.scan(params).promise().then(function(data) {
	console.log(data);
}).catch(function (error) {
	console.log(error)
})
8
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?