[SERVER-28472] How to know the collation of a collection Created: 24/Mar/17  Updated: 06/Feb/18  Resolved: 24/Mar/17

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

Type: Improvement Priority: Major - P3
Reporter: Kindox Assignee: Ramon Fernandez Marina
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

I created a collection explicitly in MongoDB 3.4 in order to define the collation:

db.createCollection("mycoll", {collation: {
  "locale": "en_US", 
  "strength": 1, 
  "caseLevel": false, 
  "numericOrdering": false, 
  "maxVariable": "punct", 
  "caseFirst": "off", 
  "alternate": "non-ignorable", 
  "normalization": false, 
  "backwards": false
}})

Now I want to check the collation associated with that collection but I can't find a command to show that information. I tested the following commands:

db.mycoll.stats()
db.runCommand({collStats: "mycoll"})

After reviewing all the output from the last command I found the collation under the indexDetails section inside _id index but it's the index collation not the collection collation. Take in account that if collection was created with autoIndexId=false then indexDetails is missed. I also test the collection using MongoDB Compass but I can't find the collation either so:

How to know the collation of a specific collection?

Thanks



 Comments   
Comment by Kindox [ 24/Mar/17 ]

Awesome! Thanks!

Comment by Ramon Fernandez Marina [ 24/Mar/17 ]

kindox, since Dan answered your question I'm going to close this ticket. Please note that the SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag, where your question will reach a larger audience. A question like this involving more discussion would be best posted on the mongodb-user group. See also our Technical Support page for additional support resources.

Regards,
Ramón.

Comment by Daniel Pasette (Inactive) [ 24/Mar/17 ]

you can get the collection information via the shell using the db.getCollectionInfos helper which is calling the listCollections command under the hood.

MongoDB Enterprise > db.getCollectionInfos({name: 'mycoll'})
[
	{
		"name" : "mycoll",
		"type" : "collection",
		"options" : {
			"collation" : {
				"locale" : "en_US",
				"caseLevel" : false,
				"caseFirst" : "off",
				"strength" : 1,
				"numericOrdering" : false,
				"alternate" : "non-ignorable",
				"maxVariable" : "punct",
				"normalization" : false,
				"backwards" : false,
				"version" : "57.1"
			}
		},
		"info" : {
			"readOnly" : false
		},
		"idIndex" : {
			"v" : 2,
			"key" : {
				"_id" : 1
			},
			"name" : "_id_",
			"ns" : "test.mycoll",
			"collation" : {
				"locale" : "en_US",
				"caseLevel" : false,
				"caseFirst" : "off",
				"strength" : 1,
				"numericOrdering" : false,
				"alternate" : "non-ignorable",
				"maxVariable" : "punct",
				"normalization" : false,
				"backwards" : false,
				"version" : "57.1"
			}
		}
	}
]

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