我的DynamoDB表确实具有一个索引名称:具有分区键的countryStateBusinessUnit-submittedAtId-index是countryStateBusinessUnit(字符串),而排序键是submittedAtId(字符串)。
Sample of record is :
{
"actionRequested": "Approve",
"altMobileNo": null,
"appState": "Approved",
"businessUnit": "DStv",
"comments": "test2",
"company": {
"dealerNo": " ",
"id": " ",
"name": " "
},
"country": "MOZ",
"countryStateBusinessUnit": "MOZ\*Approved\*DStv",
"dob": "1992-02-05",
"email": true,
"emailAddress": "declankelly1@gmail.com",
"firstName": "shana",
"id": "e7a48235-638f-436c-ac67-a4260891c22a",
"idPassportLoc": "http://location.jpg",
"lang": "en",
"lastName": "shamase",
"loc1": {
"lat": "-19.570135",
"lon": "34.72598070000004",
"name": "213, Dondo, Mozambique"
},
"loc2": {
"lat": "-18.9480626",
"lon": "32.85425220000002",
"name": "6, Manica, Mozambique"
},
"mobileNo": "+258 11 111 1111",
"photoLoc": "http://location.jpg",
"refNo": "BOE-41-TXY",
"sms": false,
"submittedAt": "2017-06-12T14:22:02.674Z",
"submittedAtId": "2017-06-12T14:22:02.674Z\*e7a48235-638f-436c-ac67-a4260891c22a",
"tools": [
{
"code": "Toolbox",
"owned": true
},
{
"code": "cableclips",
"owned": true
},
{
"code": "cablecutter",
"owned": true
},
{
"code": "cablestrippers",
"owned": true
},
{
"code": "cableties",
"owned": true
},
{
"code": "compressionf",
"owned": true
},
{
"code": "compressiontool",
"owned": true
},
{
"code": "drillingmachine",
"owned": true
},
{
"code": "fieldstrengthmeter",
"owned": true
},
{
"code": "fishtape",
"owned": true
},
{
"code": "hammer",
"owned": true
},
{
"code": "insulationtape",
"owned": true
},
{
"code": "screwdriver",
"owned": true
},
{
"code": "spanners",
"owned": true
},
{
"code": "stanley",
"owned": true
},
{
"code": "stepladder",
"owned": true
}
],
"trainingConfirmed": [
{
"code": "CustomerService",
"confirmed": true,
"proofLocation": "https://location.jpg"
},
{
"code": "one_training",
"confirmed": true,
"proofLocation": "https://location.jpg"
},
{
"code": "two_training",
"confirmed": true,
"proofLocation": "https://location.jpg"
},
{
"code": "product_knowledge",
"confirmed": true,
"proofLocation": "https://location.jpg"
},
{
"code": "sales",
"confirmed": true,
"proofLocation": "https://location.jpg"
},
{
"code": "abc_dealer",
"confirmed": true,
"proofLocation": "https://location.jpg"
},
{
"code": "vms",
"confirmed": true,
"proofLocation": "https://location.jpg"
}
],
"trainingRequested": [
{
"code": "two_training",
"levelCode": true,
"requested": true
},
{
"code": "abc_dealer",
"levelCode": null,
"requested": true
}
],
"tsAndCsAccepted": true,
"updatedAt": "2018-02-09T08:04:30.868Z"
}
我尝试使用下面的查询,但是没有用:
requestParam = {
TableName: stages.toStageQualifiedResourceName(config.ICApplicationTableName, context.stage, context),
IndexName: "country-state-index",
KeyConditionExpression: "country = :cntry and #state = :state",
ExpressionAttributeNames:{
"#state": "state"
},
ExpressionAttributeValues: {
":cntry": request.countryId.toUpperCase(),
":state": request.appState
},
ProjectionExpression: "id, firstName, lastName, appState, dob, submittedAt, company, businessUnit, updatedAt",
Limit: request.limit,
ScanIndexForward: false
};
if (fromDate && toDate) {
requestParam.ExpressionAttributeValues[":fromDte"] = fromDate;
requestParam.ExpressionAttributeValues[":toDte"] = toDate;
requestParam['FilterExpression'] = "submittedAtId > :fromDte and submittedAtId < :toDte";
}
else {
if (fromDate || toDate) {
if (fromDate) {
requestParam.ExpressionAttributeValues[":fromDte"] = fromDate;
requestParam['FilterExpression'] = "submittedAtId > :fromDte";
}
if (toDate) {
requestParam.ExpressionAttributeValues[":toDte"] = toDate;
requestParam['FilterExpression'] = "submittedAtId < :toDte";
}
}
}
}
if (request.exclusiveStartKey && request.exclusiveStartKey.trim().length > 0) {
var exKey = request.exclusiveStartKey.split(",");
requestParam.ExclusiveStartKey = {
id: exKey[0],
submittedAtId: exKey[1],
countryStateBusinessUnit: exKey[2]
};
}
有人可以告诉我如何从&到日期查询国家,州(appState)和可选(我们将与SubmittedAt或SubmittedAtId进行比较)。我还用以下详细信息创建了一个索引:
另一个新的索引名称:具有分区键的country-state-index是country(String),排序键是state(String)。请让我知道没有businessUnit时如何查询?