MongoDB Developer
Atlas
plus
Sign in to follow topics
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
Facebook Icontwitter iconlinkedin icon
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.

Facebook Icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Tutorial

Build Your Own Function Retry Mechanism with Realm


Jul 19, 2022
Tutorial

Implement Read and Create Operations in React Using the Atlas GraphQL API CRUD


Nov 01, 2022
Tutorial

Storing Binary Data with MongoDB and C++


Sep 18, 2023
Tutorial

Influence Search Result Ranking with Function Scores in Atlas Search


Feb 03, 2023
Table of Contents
  • 1. Single field