0

嗨,我知道以下错误:

提供的关键元素与架构不匹配

这里有一些答案,但没有一个对我有帮助,因为我已经将这些建议应用于我的问题并且它仍然存在。

我正在为我的数据库使用 Dynamoose 和 Koa.js,这里的后端是我的模型模式:

const userSchema = new dynamoose.Schema(
  {
    name: {
      type: String,
      trim: true,
      required: true,
      max: 32,
    },
    email: {
      type: String,
      trim: true,
      required: true,
      unique: true,
      lowercase: true,
      hashKey: true,
    },
    hashedPassword: {
      type: String,
      required: true,
    },
    salt: String,
    resetPasswordLink: {
      data: String,
      default: '',
    },
  },
  { timestamps: true },
)

如您所见,我选择email了我的哈希键,因为它既是必需的又是唯一的。

这是我的控制器代码:

exports.signup = async (ctx) => {
  if (ctx.status === 200) {
    const { name, email, password } = ctx.request.body

    try {
      const foundUser = await User.get({ email })

      //...

    } catch (error) {
      console.log(error)
    }
  }
}

当我使用名称、电子邮件和密码的 json 值发出发布请求时,我收到以下错误。我也尝试过User.get(email)两者都抛出相同的错误。这是控制台完整记录的内容:

{
  message: 'The provided key element does not match the schema',
  code: 'ValidationException',
  time: 2020-11-03T09:13:31.617Z,
  requestId: '63C8C3G4UU3CGOT1A96KGF8TONVV4KQNSO5AEMVJF66Q9ASUAAJG',
  statusCode: 400,
  retryable: false,
  retryDelay: 41.812765243942465
}

在此处找到的常用解决方案告诉我将我正在搜索的内容与哈希键(AWS 文档中的分区键)相匹配。当我通过电子邮件搜索并将电子邮件设置为我的哈希键时,我已经这样做了。有人可以帮我解决这个问题吗?

4

1 回答 1

0

根据评论中的@karjan,我没有在 AWS 上创建表。我曾假设 Dynamoose 会为我创建表格,但事实并非如此。

于 2020-11-03T12:22:47.757 回答