appsmith
appsmith copied to clipboard
[Task]: Write MongoDB script for identifying data inconsistency w.r.t. JS object
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
[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 : []}
}
https://miro.com/app/board/uXjVP-JKE-s=/
https://www.notion.so/appsmith/Data-inconsistencies-w-r-t-JS-Objects-c58f124fe20e4415b5c0e180b423b0be