1개 답변
- 최신
- 최다 투표
- 가장 많은 댓글
1
My assumption is you are trying to do a BatchGetItem
on a Global Secondary Index (GSI) which is not possible, this is because items in a GSI are not required to be unique, however, they are required to be unique for GetItem
and BatchGetItem
.
You can do one of 2 things:
- Send multiple
Query
calls - Send a PartiQL
ExecuteStatement
call
// Declare function
const exStatement = statement => {
db.executeStatement({
Statement: statement
})
.promise() // Promise
.then(res => {
console.log(JSON.stringify(res))
})
.catch(err => console.log(err))
}
//Call function
exStatement(`SELECT * from "Feed"."feedByProfileID" where profileID IN ['my_first_id','my_second_id']`) // Up to 50 PK's
I tried PartiQL statement but the problem is that I need to order the items by date which seems to be impossible with PartiQL.
PartiQL orders the same way all other API's provide order, by the
sort key
. If you do not havedate
as your GSI sort key, you will need to re-create your index to include that.Can I use the
createdAt
attribute which is generated automatically or I have to create my own attribute. This is my first time using DynamoDB so I still don't get its concepts clearly.yes you can, you can use createdAt as the GSI Sort Key
type Feed @model @auth(rules: [{allow: private}]){ id: ID! @primaryKey(sortKeyFields: ["dateCreated"]) profileID: String @index(name: "feedByProfileID") dateCreated: AWSDateTime! }
I reconstructed the model like this, but I still get this error "Must have at least one non-optional hash key condition in WHERE clause when using ORDER BY clause."