0

I'm inserting a nested document in mongo using mongoose.

{
    "_id": "56dea517302071934eae7913",
    "name": "abc",
    "counter": [
    {
        "name": "xyz",
        "count": 1,
    }
    ]
}

But On querying Mongo I get doc like:

    {
        "_id": "56dea517302071934eae7913",
        "__v": 0   //extra field 
        "name": "abc",
         "counter": [
          {
            "name": "xyz",
             "count": 1,
          }
       ]
      }

Due to the extra "__v" field in counter array object, the sha1 of the input and output does't match.

Is there any way to prevent it from happening? Or any other way to check data integrity?

Prasad
  • 1,562
  • 5
  • 26
  • 40
Shipra
  • 1,259
  • 2
  • 14
  • 26
  • Documented `{ "versionKey": false }` in the schema options. You should not be hashing objects anyway, there are far better approaches. – Blakes Seven Mar 08 '16 at 10:59
  • 1
    Possible duplicate of [What is the "\_\_v" field in MongoDB](http://stackoverflow.com/questions/12495891/what-is-the-v-field-in-mongodb) – Blakes Seven Mar 08 '16 at 11:00
  • @BlakesSeven, Can you tell me what should be done for checking data integrity? `{ "versionKey": false }` schema options is removing the __v property. – Shipra Mar 08 '16 at 11:01
  • 1
    Far to broad and opinion based. MongoDB actually does wire protocol checks by default from what is sent from the dirver to the server. So "data integrity" can be interpretted in many ways. Best ask another question being more direct to what you think you mean. This is too focused on the `__v` property being added ( and also easy for other middleware to add other data ) and how to turn the creation of that property off. Which has already been answered in the referenced questions answers. – Blakes Seven Mar 08 '16 at 11:07

0 Answers0