Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Fix: MongoDB Robomongo: db.data.find(...).collation is not a function?
The collation feature was introduced in MongoDB version 3.4. If you're encountering the error "collation is not a function", you're likely using an older MongoDB version or an outdated client like Robomongo that doesn't support this feature.
Check MongoDB Version
First, verify your MongoDB version to ensure it's 3.4 or higher ?
db.version()
4.0.5
Create Sample Data
Let's create a collection with an index that uses collation and insert test documents ?
db.collationExample.createIndex(
{Value: 1},
{collation: {locale: "en", strength: 1}}
)
{
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
db.collationExample.insertMany([
{'Value': 'x'},
{'Value': 'X'},
{'Value': 'Y'},
{'Value': 'a'},
{'Value': 'á'}
])
{
"acknowledged" : true,
"insertedIds" : [
ObjectId("5e038a3cf5e889d7a51994f5"),
ObjectId("5e038a48f5e889d7a51994f6"),
ObjectId("5e038a49f5e889d7a51994f7"),
ObjectId("5e038a49f5e889d7a51994f8"),
ObjectId("5e038a4bf5e889d7a51994f9")
]
}
View All Documents
db.collationExample.find().pretty()
{ "_id" : ObjectId("5e038a3cf5e889d7a51994f5"), "Value" : "x" }
{ "_id" : ObjectId("5e038a48f5e889d7a51994f6"), "Value" : "X" }
{ "_id" : ObjectId("5e038a49f5e889d7a51994f7"), "Value" : "Y" }
{ "_id" : ObjectId("5e038a49f5e889d7a51994f8"), "Value" : "a" }
{ "_id" : ObjectId("5e038a4bf5e889d7a51994f9"), "Value" : "á" }
Using Collation Function
The collation function performs case-insensitive and accent-insensitive matching ?
db.collationExample.find({ Value: "a" }).collation({ locale: "en", strength: 1 })
{ "_id" : ObjectId("5e038a49f5e889d7a51994f8"), "Value" : "a" }
{ "_id" : ObjectId("5e038a4bf5e889d7a51994f9"), "Value" : "á" }
Solution for Robomongo
If you're using Robomongo (now Robo 3T), upgrade to a newer version that supports MongoDB 3.4+ features. Alternatively, use MongoDB Compass or the standard mongo shell for collation support.
Conclusion
Collation requires MongoDB 3.4+ and compatible clients. Upgrade your MongoDB version and client tools if encountering "collation is not a function" errors. The feature enables powerful case-insensitive and locale-specific text matching.
