Skip to content

Response formatting seems misleading. #74

@ilyaLibin

Description

@ilyaLibin

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'
});
 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions