Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mongodb-preview.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

This page explains how to specify a default collation for a view. Use a default view collation when string comparison rules, such as accent or letter-case handling, must be consistent for every query that reads from the view.

Example

Create a places collection with the following documents:
db.places.insertMany([
   { _id: 1, category: "café" },
   { _id: 2, category: "cafe" },
   { _id: 3, category: "cafE" }
])
The following operation creates a view, specifying collation at the view level:
db.createView(
   "placesView",
   "places",
   [ { $project: { category: 1 } } ],
   { collation: { locale: "fr", strength: 1 } }
)
The following operation uses the view’s collation:
db.placesView.countDocuments( { category: "cafe" } )
The operation returns 3.
  • You can specify a default collation for a view at creation time. If no collation is specified, the view’s default collation is the “simple” binary comparison collator. That is, the view does not inherit the collection’s default collation.
  • String comparisons on the view use the view’s default collation. An operation that attempts to change or override a view’s default collation will fail with an error.
  • If creating a view from another view, you cannot specify a collation that differs from the source view’s collation.
  • If performing an aggregation that involves multiple views, such as with $lookup or $graphLookup, the views must have the same collation.