[COMPASS-274] Converting type names to numbers in doc validation rule builder makes JSON less readable Created: 03/Nov/16  Updated: 14/Nov/18  Resolved: 14/Nov/18

Status: Closed
Project: Compass
Component/s: UI / UX
Affects Version/s: None
Fix Version/s: 1.18.0

Type: Task Priority: Major - P3
Reporter: Andrew Morgan Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File object_checks.png    
Epic Link: COMPASS-2227
Story Points: 2

 Description   

I created doc validation rules using type names (see attached) but Compass then converts them to the numeric equivalent in the JSON output and the rule that's added to MongoDB. It would be simpler for people to understand the rules if Compass kept the name instead.

rules.js

{
  "name": {
    "$type": 3
  },
  "name.first": {
    "$type": 2
  },
  "name.last": {
    "$type": 1
  },
  "social.twitter": {
    "$type": 4
  }
}
 
db.getCollectionInfos({name:"people"})
[
	{
		"name" : "people",
		"type" : "collection",
		"options" : {
			"validator" : {
				"name" : {
					"$type" : 3
				},
				"name.first" : {
					"$type" : 2
				},
				"name.last" : {
					"$type" : 1
				},
				"social.twitter" : {
					"$type" : 4
				}
			},
			"validationLevel" : "strict",
			"validationAction" : "error"
		},
		"info" : {
			"readOnly" : false
		},
		"idIndex" : {
			"v" : 2,
			"key" : {
				"_id" : 1
			},
			"name" : "_id_",
			"ns" : "clusterdb.people"
		}
	}
]

Scope of the ticket:

  • change type value to its string alias
  • change tests to reflect this


 Comments   
Comment by Asya Kamsky [ 24/Sep/17 ]

I take it back - it keeps string if that's what the rule starts out as, when I add a new rule it converts it to number like Andrew observed.

Still it doesn't handle $type="number" possibly related to that...

Comment by Asya Kamsky [ 24/Sep/17 ]

I noticed in 1.9 beta2 that it seems to have kept the strings. On the other hand, it doesn't seem to know $type "number" so when I had a rule like that, it only displays as JSON and not in rule builder so I can't edit it. Should I file a separate bug or is this part of types etc?

Comment by Thomas Rueckstiess [ 10/Mar/17 ]

String aliases for types were converted to numbers for backwards-compatibility with older servers. However, we only use these in the Document Validation context, which was also added in 3.2, together with string aliases.

We can therefore safely send the string alias instead of the number.

See here: https://github.com/10gen/compass/blob/master/src/internal-packages/validation/lib/components/rule-categories/type.jsx#L13

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