[SERVER-36696] Add description field for collections Created: 16/Aug/18  Updated: 25/Apr/19  Resolved: 24/Aug/18

Status: Closed
Project: Core Server
Component/s: Usability
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Leandro Jordao Assignee: Asya Kamsky
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Participants:

 Description   

We know that the mongo does not save metadata about the collection, but have same features to help do decrease the size of database.

We usually use short names to fields, to help do decrease the size of the database (usually our application do that for us), but it does not help when you want to do a search on database in the mongoldb console. The mongo already had that feature for indexes, I just don't know the size of the description in the index. I hope there is no limit or large enougth to put all information we need about the collection

It will be nice, if we can put a description in the collections, because we can specify the what are the fields, what they represent in the application.

I think that is reasonable, but it's up to you guys, it's an idea.



 Comments   
Comment by Asya Kamsky [ 24/Aug/18 ]

leandroldantas

You can use the existing schema validation feature for this.

You can omit all actual validation directives and only use "description" field which the validator treats as a no-op.

Example:

db.createCollection("people", { validator: {
	"$jsonSchema" : {
		"bsonType" : "object",
		"description" : "Company CO 2018. This collection is used to put all information the is present in the Las Vegas Cassino Hotel.",
		"properties" : {
				"LU" : {
					"description" : "LASTUPDATE, when it was updated"
				},
				"O" : {
					"description" : "ORIGINATOR_NUMBER, more description"
				},
				"D" : {
					"description" : "DESTINATION_NUMBER, blah blah"
				},
				"XXX" : {
					"description" : "more prose"
				}
		}
	}
}
 

To see existing validators for collection you would use listCollections command or the shell helper getCollectionInfos :

db.getCollectionInfos({name:"people"})
[
	{
		"name" : "people",
		"type" : "collection",
		"options" : {
			"validator" : {
				"$jsonSchema" : {
					"bsonType" : "object",
					"description" : "Company CO 2018. This collection is used to put all information the is present in the Las Vegas Cassino Hotel.",
					"properties" : {
						"LU" : {
							"description" : "LASTUPDATE, when it was updated"
						},
						"O" : {
							"description" : "ORIGINATOR_NUMBER, more description"
						},
						"D" : {
							"description" : "DESTINATION_NUMBER, blah blah"
						},
						"XXX" : {
							"description" : "more prose"
						}
					}
				}
			}
		},
		"info" : {
			"readOnly" : false,
			"uuid" : UUID("11892539-876d-47a9-8a9c-34904b7d8269")
		},
		"idIndex" : {
			"v" : 2,
			"key" : {
				"_id" : 1
			},
			"name" : "_id_",
			"ns" : "test.people"
		}
	}
]

Comment by Leandro Jordao [ 17/Aug/18 ]

The purpose of the description it's not to find a document in the collection.

The purpose is to describe the fields in each document in the collection.

Imagine that I have a document like that

{
 	"_id" : ObjectId("5b771669966bdc0ba243c95a"),
    	"LU" : ISODate("2018-07-23T22:08:08.000Z"),
    	"O" : "1130904692",
    	"D" : "909039166100",
}

Think, do you know what the fields "LU", "O", "D", represent in that document? It's difficult to understand what does that fields represent in that document.

We use short name for the fields to reduce the size of the database.

The original document could be like that

{
 	"_id" : ObjectId("5b771669966bdc0ba243c95a"),
    	"LASTUPDATE" : ISODate("2018-07-23T22:08:08.000Z"),
    	"ORIGINATOR_NUMBER" : "1130904692",
    	"DESTINATION_NUMBER" : "909039166100"
}

We work with telecom company, and easy easy we have a collection with more than 200.000.000 document's and the document has more than 50 fields.

Comment by Ramon Fernandez Marina [ 17/Aug/18 ]

leandroldantas, please note that as a workaround you can insert this document in the collection itself; for example:

db.people.insert({_id:"_description_doc_", description: "Company CO 2018. This collection is used to put all information the is present in the Las Vegas Cassino Hotel. Here are the description of the fields, LU : LASTUPDATE, ......." })

Then you can let everyone to search for the dcument with "description_doc" _id.

Comment by Nick Brewer [ 17/Aug/18 ]

leandroldantas Thanks for clarifying. I'm passing this along to our Query team for evaluation.

-Nick

Comment by Leandro Jordao [ 16/Aug/18 ]

@Nick.Brewer I don't know if was clear. But I'll try to explain the idea better.

The field "description" that I said, is to be present in the db.createCollection(). Today we don't have that option.

Ex: db.createCollection("people",

{ description: "Company CO 2018. This collection is used to put all information the is present in the Las Vegas Cassino Hotel. Here are the description of the fields, LU : LASTUPDATE, ......." }

)

In my example above, I explained what does the field LU represent. If I didn't put that information, one DBA or Developer could not know what does the field represent.

Been a DBA, I could run the command like db.peoople.description() to get a description of the collection and to know what each field in that collection represent.

It will be a metadata of our collection, we don't have to see the log to show this description, it's a long way to see to show that descripton and think about the time that will you spend the command that created the collection. I don't know how difficult is that, but it shows to simple, and helpful for the mongoldb users.

Comment by Nick Brewer [ 16/Aug/18 ]

leandroldantas With the introduction of the WiredTiger storage engine and on-disk compression, the potential performance gain acquired by using shortened field names is likely outweighed by the added complexity that they introduce.

Note that SERVER-29794 would allow for adding comments to CRUD operations, which would potentially allow you to include definitions for fields in a comment when you insert them. However these comments would only be accessible via logs, meaning it wouldn't provide you with an easy way to determine this information from the shell.

-Nick

Generated at Thu Feb 08 04:43:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.