如何在mongoose中定义时自动增加mongodb中的特定属性?

问题描述

我正在创建一个模型,在该模型中,我希望特定属性(例如incAttr:Number)以其初始值为0自动递增。我的伪代码如下所示:

model.js

var mongoose = require('mongoose')
var CollSchema = mongoose.Schema({
  // someway to auto increment
  incAttr: Number,attr2: String
})
module.exports = mongoose.model('CollName',CollSchema)

router.js

var model = require('./model.js')
var newModel = new model({
  attr2: "sample"
})
newModel.save().

谁能建议一种实现自动增量的方法

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)