【问题标题】:Mongoose custom attribute name mappingMongoose 自定义属性名称映射
【发布时间】:2015-06-09 17:45:23
【问题描述】:

我有一个带有“选项”属性的集合,但它是 Mongoose 中的保留字。 我不想更改我在 MongoDB 中的整个集合以避免这个问题,所以我想知道在 Mongoose 中定义新模式时是否可以自定义映射。

这是我当前的架构

var QuestionSchema = new Schema({
  question: {
    type: String,
    required: true,
    trim: true
  },
  answer: {
    type: String,
    required: true
  },
  options: [String]
});

也许我可以在 Mongoose 中使用 ops 而在 MongoDB 中使用 options

谢谢

【问题讨论】:

    标签: mongoose mean-stack


    【解决方案1】:

    我在使用 options 属性时遇到了完全相同的问题。我最终只是在我的数据库中使用 opts。如果你真的不想这样做,你可以看看 virtuals 中内置的猫鼬。作为替代 this 库可以满足您的需求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多