我是猫鼬的新手,我有一个像这样的猫鼬模式:
var user = mongoose.Schema({
userID: {
type: String,
required:true
},
seq: {
type: Number,
default: 0
},
firstname: {
type: String
},
lastname: {
type: String
},
dob: {
type: String
},
email: {
type: String,
required: true
},
username: {
type: String,
required: true
},
displayname: {
type: String
},
password: {
type: String,
required: true
},
mobile: {
type: String
},
profilePic: {
type: String
},
city: {
type: String
},
gender: {
type: String
},
profileType: {
type: String,
required: true
},
profileId: {
type: String
},
isActive: {
type: Number
},
ageVerified: {
type: String
},
ipAddress: {
type: String
},
key: {
type: String
},
osType: {
type: String
},
osVersion: {
type: String
},
deviceName: {
type: String
},
joinedDate: {
type: String
},
connectedAccounts: [{
profileType: {
type: String
},
profileId: {
type: String
},
email: {
type: String
}
}]
}, {collection: 'user'});
请注意,userID 是一个自动递增数字字段,用于使用 mongoose 查询插入值,例如:
new user(contents).save(function (err,doc){};
'contents' 是一个对象,其中包含除 userID 之外的所有字段的数据,这里我的问题是如何在为其他字段插入记录的同时插入 userID 的值(自动增量数字)?我参考这个link设置自动增量值...但我不知道如何在猫鼬中使用它?