[COMPASS-5015] Duplicating View in Compass picks up the view's source collection's name as the DB name Created: 16/Aug/21  Updated: 29/Oct/23  Resolved: 09/Sep/21

Status: Closed
Project: Compass
Component/s: Compass
Affects Version/s: 1.28.1
Fix Version/s: 1.29.4

Type: Bug Priority: Major - P3
Reporter: Harshad Dhavale Assignee: Rhys Howell
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File ADMIN_COmpassView_Creation_Takes_DBName_As_SourceCollectionName.png     PNG File COmpassView_Creation_Takes_DBName_As_SourceCollectionName.png    
Story Points: 3
Documentation Changes: Not Needed
Sprint: Iteration Kampala

 Description   

Problem Statement/Rationale

In Compass, when you click on the eillipsis next to a View, click "Duplicate View", enter some view name, and click the "Duplicate" button, then it throws an error. The error that it throws depends on the role and privileges the user has, but the *root-cause of the error is same*. Specifically, the "Duplicate View" functionality erroneously tries to duplicate the view in a database whose name is the view's source collection's name.

For example, consider this test collection called survey:

PRIMARY> db.survey.find()
{ "_id" : 1, "empNumber" : "abc123", "feedback" : { "management" : 3, "environment" : 3 }, "department" : "A" }

I created a view named managementFeedback on the above collection:

PRIMARY> db.createView(
...    "managementFeedback",
...    "survey",
...    [ { $project: { "management": "$feedback.management", department: 1 } } ]
... )
{
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1629140171, 1),
		"signature" : {
			"hash" : BinData(0,"bHBmefZ5gCFjO5/HT+tLSkRxA2Q="),
			"keyId" : NumberLong("6940972140258656257")
		}
	},
	"operationTime" : Timestamp(1629140171, 1)
}
 
MongoDB Enterprise HDFTS-shard-0:PRIMARY> db.managementFeedback.find()
{ "_id" : 1, "department" : "A", "management" : 3 }

As you can observe above, survey is the name of the collection.

Now, from Compass versions 1.25.0 as well as 1.28.1, if I try to duplicate the collection, I get errors. The error that I get if I login to Compass as user with admin level privileges, is as follows:

Invalid input namespace, survey.

And the error that I get if I login to Compass as user with non-admin level privileges, is as follows:

not authorized on survey to execute command { create: "xyz", viewOn: "", pipeline: [ { $project: { management: "$feedback.management", department: 1 } } ], lsid: { id: UUID("1af90bb8-52be-41f4-afb7-7361347ed059") }, $clusterTime: { clusterTime: Timestamp(1629153553, 1), signature: { hash: BinData(0, AA0B7505B09DD8AF43F8347FF1ABA5F704900771), keyId: 6940972140258656257 } }, $db: "survey" }

Note above in both errors that the dbname shows as survey. In other words, Compass erroneously tries to duplicate the view in a database whose name is the view's source collection's name.
 

Steps to Reproduce

  • Create a view on a collection.
  • From Compass > click on the ellipsis next to the View name > click "Duplicate View" > enter some view name > click the "Duplicate" button.

Expected Results

Compass should not choose the view's source collection's name as the DB name for creating the duplicated view, and the View should be duplicated correctly and successfully.

Actual Results

The view creation fails with the above errors.

Additional Notes

Observed in Compass versions 1.25.0 as well as 1.28.1.



 Comments   
Comment by Githook User [ 10/Sep/21 ]

Author:

{'name': 'Rhys', 'email': 'Anemy@users.noreply.github.com', 'username': 'Anemy'}

Message: fix(compass-sidebar): pass source namespace when duplicating view COMPASS-5015 (#2440)
Branch: COMPASS-5046-add-e2e-fixture
https://github.com/mongodb-js/compass/commit/24e647380a11c5ac0fcfa10567034944fb7141c5

Comment by Githook User [ 09/Sep/21 ]

Author:

{'name': 'Rhys', 'email': 'Anemy@users.noreply.github.com', 'username': 'Anemy'}

Message: fix(compass-sidebar): pass source namespace when duplicating view COMPASS-5015 (#2440)
Branch: main
https://github.com/mongodb-js/compass/commit/24e647380a11c5ac0fcfa10567034944fb7141c5

Generated at Wed Feb 07 22:38:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.