dynamodb icon indicating copy to clipboard operation
dynamodb copied to clipboard

Response formatting seems misleading.

Open ilyaLibin opened this issue 4 years ago • 2 comments

Hi! I'm using this query in order to get the latest item for a specific hash key. (range key is createdAt).

  const item = await Campaign.query('222')
    .limit(1)
    .descending()
    .exec().promise().then((data) => {
      if (!data[0].Count) return null;
      return data[0].Items[0].attrs
    })

It seems like no matter what's the limit, the data always comes back an array of 1 object. Why is it an array in the first place? Is there a case when it's not an array on 1? Is there any built-in way to get the response as a plain array of documents?

const Campaign = dynamo.define('Campaign', {
  hashKey: 'anonymousId',
  rangeKey: 'createdAt',
  timestamps: true,
  schema: {
    anonymousId: Joi.string(),
    utm_source: Joi.string(),
    utm_medium: Joi.string(),
    utm_content: Joi.string(),
    utm_campaign: Joi.string(),
    otherParams: Joi.string()
  },
  tableName: 'campaigns-prod'
});
 

ilyaLibin avatar Apr 04 '20 23:04 ilyaLibin

@ilyaLibin

I'm having the same issue and trying to figure out the reasoning for array as response. Were you able to make any progress with this?

valeeum avatar Jul 03 '20 23:07 valeeum

@valeeum Yeah! Switched to Dynamoose :)

ilyaLibin avatar Aug 10 '20 06:08 ilyaLibin