0
敲我的頭跟這個有幾個小時,我不明白爲什麼它不工作DynamoDB attribute_exists不起作用
我有一個DynamoDBv2表(頂級屬性顯示爲單獨列)與類的物品這些:
{
gateway: 'gateway1',
device_id: '2',
state: { temperature: 20, humidity: 30, pressure: 101049 },
timestamp: 1498331237261
},
{
gateway: 'gateway1',
device_id: '2',
state: { temperature: 20, humidity: 30, pressure: 101049, lat: 2, long: 1 },
timestamp: 1498331237262
}
主分區鍵:device_id
(字符串)
主排序關鍵字:timestamp
(號碼)
我試圖獲取具有lat
和long
屬性的特定設備的最新項目。
const docClient = new AWS.DynamoDB.DocumentClient();
const id = 2;
const params = {
TableName: 'device_telemetry',
KeyConditionExpression: 'device_id = :id',
ProjectionExpression: '#s, #lat, #lng, #ts',
FilterExpression: 'attribute_exists(#lat) AND attribute_exists(#lng)',
ExpressionAttributeNames: {
'#s': 'state',
'#lat': 'state.lat',
'#lng': 'state.long',
'#ts': 'timestamp'
},
ExpressionAttributeValues: {
':id': id.toString()
},
ScanIndexForward: false,
Limit: 1
};
const onResult = (res) => {
console.info('devices res for: ', id, res);
};
console.info('query: ', params);
docClient.query(params).promise().then(onResult);
如果我使用attribute_exists(#s)
,那麼它的工作原理,但#lat
或#long
它不
我在做什麼錯?