1

When saving an object using Mongoose, a version key property is assigned to the document.

According to the Mongoose documentation, the default value for the version key is __v

I am trying to access this version number property via the mongoose object using the following commands, but both calls return a value of undefined:

myObject.__v
myObject["__v"]

If I view the object directly via a logger then the property is visible and assigned a value. If I use JSON.stringify( myObject ) then I can access the __v property using a regular expression.

More interestingly though, if I iterate through the keys of the object I see properties called _version and __version but no __v property.

Can anyone tell me how to access the __v property directly?

4

1 回答 1

1

You can use myObject.get('__v').

于 2013-08-28T09:18:52.317 回答