Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the command to know the collation of some collection?

Tags:

mongodb

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 but I had no luck

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

so What is the command to know the collation of some collection?

Edit: Analyzing the output of commands above I found collator= under wiredTiger storage engine so I am wondering if it's the place where collation should appear but why is it empty?

Edit: After reviewing all the output from db.runCommand({collStats: "mycoll"}) 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 so: how to know the collation of some collection in any case?

like image 916
Delmo Avatar asked Mar 23 '17 21:03

Delmo


1 Answers

Finally I wrote to MongoDB guys since I can't find an answer in the web so they replied me with the helper to know the collation:

db.getCollectionInfos({name: 'mycoll'})

Output

[
    {
        "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" : "testdb.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"
            }
        }
    }
]
like image 126
Delmo Avatar answered Nov 13 '22 09:11

Delmo