appsmith icon indicating copy to clipboard operation
appsmith copied to clipboard

[Task]: Write MongoDB script for identifying data inconsistency w.r.t. JS object

Open subrata71 opened this issue 2 years ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Description

TBD

Steps To Reproduce

N/A

Public Sample App

No response

Issue video log

No response

Version

Cloud / Self Hosted

subrata71 avatar Nov 25 '22 05:11 subrata71

[1] https://github.com/appsmithorg/appsmith/issues/13302 [Bug]: When an action is deleted, remove its reference from the action collection as well

===================== Aggregation Pipeline

Base Collection: actionCollection

match
{
  "deletedAt": {$exists: false},
  "unpublishedCollection.defaultToBranchedActionIdsMap": {$ne: {}}
}
addFields
{
  actions: {$objectToArray: "$unpublishedCollection.defaultToBranchedActionIdsMap"}
}
unwind
{
  path: "$actions",
  preserveNullAndEmptyArrays: true
}
lookup
{
    "from": "newAction",
    "let": { "actionId": "$actions.k"},
    "pipeline": [
      { "$addFields": { "actionId": { "$toString": "$_id" }}},
      { "$match": { "$expr": { "$eq": [ "$actionId", "$$actionId" ] } } }
    ],
    "as": "newAction"
}
unwind
{
  path: "$newAction",
  preserveNullAndEmptyArrays: false
}
match
{
  "newAction.unpublishedAction.deletedAt": {$exists: true}
}

[2] Some JS action doesn't have collectionId (Orphan JS actions)

Base Collection: newAction

{pluginType: "JS", "unpublishedAction.collectionId": {$exists: false}, "unpublishedAction.deletedAt": {$exists: false}}

[3] actionCollection having empty actionIdMap although there exist valid actions with the same collectionId

Base Collection: newAction

match
{
  pluginType: "JS",
  deletedAt: {$exists: false},
  "unpublishedAction.collectionId": {$exists: true}
}

lookup
{
    "from": "actionCollection",
    "let": { "colId": "$unpublishedAction.collectionId"},
    "pipeline": [
      { "$addFields": { "colId": { "$toString": "$_id" }}},
      { "$match": { "$expr": { "$eq": [ "$colId", "$$colId" ] } } }
    ],
    "as": "result"
}

unwind
{
  path: "$result",
  preserveNullAndEmptyArrays: false
}

match
{
  "result.unpublishedCollection.defaultToBranchedActionIdsMap": {$eq: {}}
}

[4] Some JS actions have no corresponding actionCollection although there's collectionId found in the action

Base Collection: newAction

match
{
  pluginType: "JS",
  "unpublishedAction.collectionId": {$exists: true},
  "unpublishedAction.deletedAt": {$exists: false}
}

lookup
{
    "from": "actionCollection",
    "let": { "colId": "$unpublishedAction.collectionId"},
    "pipeline": [
      { "$addFields": { "colId": { "$toString": "$_id" }}},
      { "$match": { "$expr": { "$eq": [ "$colId", "$$colId" ] } } }
    ],
    "as": "result"
}
match
{
  result: {$eq : []}
}

subrata71 avatar Dec 01 '22 19:12 subrata71

https://miro.com/app/board/uXjVP-JKE-s=/

subrata71 avatar Dec 01 '22 19:12 subrata71

https://www.notion.so/appsmith/Data-inconsistencies-w-r-t-JS-Objects-c58f124fe20e4415b5c0e180b423b0be

subrata71 avatar Dec 01 '22 19:12 subrata71