【问题标题】:Mongo-mongoose What is the best way to create categorical typeMongo-mongoose 创建分类类型的最佳方法是什么
【发布时间】:2020-10-15 16:31:48
【问题描述】:

我正在使用带有 nodejs 的 mongo db,mongoose.mongoose 为每条记录创建了 id,但我想要的是相同的自动增量类型。它会从 1 或 0 开始然后增加。

是否有任何架构类型可以制作它。它将用于 api 的分类结果。

谢谢。

我的尝试是

category_type: {
  type     : Number,
  required : true,
  unique   : true,
  validate : {
    validator : Number.isInteger,
    message   : '{VALUE} is not an integer value'
  }
}

可以增量吗?

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    从 mongoose 本身(v5 或更低版本)开始,没有这种自增整数模式类型。但是,我遇到了一个可以提供帮助的插件,请在此处查看 mongoose-auto-increment

    【讨论】:

      猜你喜欢
      • 2012-10-22
      • 2010-12-17
      • 2021-04-22
      • 2019-10-26
      • 2012-12-03
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多