Atlas
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
Atlaschevron-right

Atlas Search Multi-Language Data Modeling

Ethan Steininger, Harshad DhavalePublished Sep 07, 2022 • Updated Sep 09, 2022
AtlasSearch
Copy Link
facebook icontwitter iconlinkedin icon
random alt
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
We live in an increasingly globalized economy. By extension, users have expectations that our applications will understand the context of their culture and by extension: language.
Luckily, most search engines—including, Atlas Search—support multiple languages. This article will walk through three options of query patterns, data models, and index definitions to support your various multilingual application needs.
To illustrate the options, we will create a fictitious scenario. We manage a recipe search application that supports three cultures, and by extension, languages: English, Japanese (Kuromoji), and German. Our users are located around the globe and need to search for recipes in their native language.

1. Single field

We have one document for each language in the same collection, and thus each field is indexed separately as its own language. This simplifies the query patterns and UX at the expense of bloated index storage.
Document:
Index:
Query:
Pros:
  • One single index definition.
  • Don’t need to specify index name or path based on user’s language.
  • Can support multiple languages in a single query.
Cons:
  • As more fields get added, the index definition needs to change.
  • Index definition payload is potentially quite large (static field mapping per language).
  • Indexing fields as irrelevant languages causing larger index size than necessary.

2. Multiple collections

We have one collection and index per language, which allows us to isolate the different recipe languages. This could be useful if we have more recipes in some languages than others at the expense of lots of collections and indexes.
Documents:
Index:
Query:
Pros:
  • Can copy the same index definition for each collection (replacing the language).
  • Isolate different language documents.
Cons:
  • Developers have to provide the language name in the index path in advance.
  • Need to potentially copy documents between collections on update.
  • Each index is a change stream cursor, so could be expensive to maintain.

3. Multiple fields

By embedding each language in a parent field, we can co-locate the translations of each recipe in each document.
Document:
Index:
Query:
Pros:
  • Easier to manage documents.
  • Index definition is sparse.
Cons:
  • Index definition payload is potentially quite large (static field mapping per language).
  • More complex query and UX.

Copy Link
facebook icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Article
How to work with Johns Hopkins University COVID-19 Data in MongoDB Atlas

May 31, 2022
Tutorial
MongoDB Atlas Data Lake Tutorial: Federated Queries and $out to AWS S3

Sep 23, 2022
Tutorial
Is it Safe to Go Outside? Data Investigation With MongoDB

Sep 23, 2022
Article
Automate the Automation on MongoDB Atlas

May 13, 2022
Table of Contents
  • 1. Single field