BlogAnnounced at MongoDB.local NYC 2024: A recap of all announcements and updatesLearn more >>
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 Dhavale2 min read • Published 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

How to Seamlessly Use MongoDB Atlas and IBM watsonx.ai LLMs in Your GenAI Applications


Nov 15, 2023 | 9 min read
Article

Keeping Your Costs Down with MongoDB Atlas Serverless Instances


Jan 23, 2023 | 3 min read
Tutorial

Authentication for Your iOS Apps with Atlas App Services


Apr 04, 2024 | 8 min read
Tutorial

How to Use Cohere Embeddings and Rerank Modules with MongoDB Atlas


Apr 04, 2024 | 10 min read
Table of Contents
  • 1. Single field