Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-41559

Can not fetch changed array elements from change streams

    • Query Execution

      Here are outputs for corresponding steps, What I need is to manipulate the deleted array item, but it seems not workable.

      1) First , here is the initial data in the database,

         there're 3 outer array items "test-0, test-1, test-2" with each has 3 inner array items "nest-test-0,nest-test-1,nest-test-3":

       

      {
          "_id": "5cf7553cc6b365a5c72f2163",
          "opendaylight-mdsal-binding-test:top": {
              "top-level-list": [
                  {
                    "name": "test-0",
                    "nested-list": [
                        {"name": "nest-test-0", "type": "nest-type-0"},
                        {"name": "nest-test-1", "type": "nest-type-1"},
                        {"name": "nest-test-2", "type": "nest-type-2"}
                    ],
                    "simple": "simple-case"
                  },
                  {
                    "name": "test-1",
                    "nested-list": [
                        {"name": "nest-test-0", "type": "nest-type-0"},
                        {"name": "nest-test-1", "type": "nest-type-1"},
                        {"name": "nest-test-2", "type": "nest-type-2"}
                    ],
                    "simple": "simple-case"
                  },
                  {
                    "name": "test-2",
                    "nested-list": [
                        {"name": "nest-test-0", "type": "nest-type-0"},
                        {"name": "nest-test-1", "type": "nest-type-1"},
                        {"name": "nest-test-2", "type": "nest-type-2"}
                    ],
                    "simple": "simple-case"
                  }
              ]
          }
      }
      

      2) Next , I pull one nested array item by calling 'collection.updateOne(...)' where 'Update' and 'UpdateOptions' like:

      Update{fieldName='opendaylight-mdsal-binding-test:top.top-level-list.$[item0].nested-list', operator='$pull', value=Document{{name=nest-test-2}}}
      UpdateOptions{upsert=true, bypassDocumentValidation=null, collation=null, arrayFilters=[And Filter{filters=[Filter{fieldName='item0.name', value=test-0}]}]}
      

      It's clear above that I specify the '$[item0]' with 'Filter{fieldName='item0.name', value=test-0}'  to delete the inner array item 'nest-test-2' from outer array item 'test-0'.

      3) After step 2), finally I recieve the change event:

      ChangeStreamDocument {
          resumeToken = {
              "_data":
                  "825CF75C47000000022B022C0100296E5A10042A6A4D3FE1F64145A8D27037F0BA45BD46645F696400645CF75C47D4CE6723E929EA0B0004"
          },
          namespace = configuration.urn: opendaylight: params: xml: ns: yang: mdsal: test: binding @2014 -
              07 - 01,
          fullDocument = Document{
              {
                _id = 5cf75c47d4ce6723e929ea0b,
                opendaylight - mdsal - binding -
                test:
                    top = Document{
                        {top - level - list =
                             [
                               Document{
                                   {name = test - 0,
                                    nested - list =
                                        [
                                          Document{{name = nest - test - 0, type = nest - type - 0}},
                                          Document{{name = nest - test - 1, type = nest - type - 1}}
                                        ],
                                    simple = simple - case}
                               },
                               Document{
                                   {name = test - 1,
                                    nested - list =
                                        [
                                          Document{{name = nest - test - 0, type = nest - type - 0}},
                                          Document{{name = nest - test - 1, type = nest - type - 1}},
                                          Document{{name = nest - test - 2, type = nest - type - 2}}
                                        ],
                                    simple = simple - case}
                               },
                               Document{
                                   {name = test - 2,
                                    nested - list =
                                        [
                                          Document{{name = nest - test - 0, type = nest - type - 0}},
                                          Document{{name = nest - test - 1, type = nest - type - 1}},
                                          Document{{name = nest - test - 2, type = nest - type - 2}}
                                        ],
                                    simple = simple - case}
                               }
                             ]}
                    }
              }
          },
          documentKey = {"_id": {"$oid": "5cf75c47d4ce6723e929ea0b"}},
          clusterTime = Timestamp{value = 6698924430749335554, seconds = 1559714887, inc = 2},
          operationType = OperationType{value = 'update'}, updateDescription = UpdateDescription {
              removedFields = [], updatedFields = {
                  "opendaylight-mdsal-binding-test:top.top-level-list.0.nested-list": [
                      {"name": "nest-test-0", "type": "nest-type-0"},
                      {"name": "nest-test-1", "type": "nest-type-1"}
                  ]
              }
          }
      }
      

      From the output we can see that it's an 'update' operation type and the 'updatedFields' is :

      {"opendaylight-mdsal-binding-test:top.top-level-list.0.nested-list": [{"name": "nest-test-0", "type": "nest-type-0"}, {"name": "nest-test-1", "type": "nest-type-1"}]}}
      

      Note 'updatedFields' above just provides data after '$pull', but I really need to see detail deleted data information "what I delete from where", an idealy output I would prefer is like kind of :

      {"opendaylight-mdsal-binding-test:top.top-level-list.0.nested-list": [{
      "array-filter": {"0": {"name": "test-0"}},
      "pulled":{"name": "nest-test-2", "type": "nest-type-2"},
      "current": {"name": "nest-test-0", "type": "nest-type-0"}, {"name": "nest-test-1", "type": "nest-type-1"}]}}
      }
      

      In this way , with 'array-filter' and 'pulled' fields, I could get the deleted data and notify listeners just like 'DataTreeChangeService' does:

      https://github.com/opendaylight/alt-datastores/blob/master/mongodb/yongo/src/main/java/org/opendaylight/datastore/yongo/impl/YongoStream.java#L155

       

       

       

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            jiehan2019 Han
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: