I'm using Mongoose
version 3 with MongoDB
version 2.2. I've noticed a __v
field has started appearing in my MongoDB
documents. Is it something to do with versioning? How is it used?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
From here:
The
versionKey
is a property set on each document when first created by Mongoose. This keys value contains the internal revision of the document. The name of this document property is configurable. The default is__v
.If this conflicts with your application you can configure as such:
new Schema({..}, { versionKey: '_somethingElse' })
回答2:
Well, I can't see Tony's solution...so I have to handle it myself...
If you don't need version_key, you can just:
var UserSchema = new mongoose.Schema({
nickname: String,
reg_time: {type: Date, default: Date.now}
}, {
versionKey: false // You should be aware of the outcome after set to false
});