Not so many languages, for the moment only two. The problem is that these documents refers to other documents, of course with the same language. In general I have public documents with uniqueId and language and then private documents with only the id. At the moment, all my documents are in the same collection and I can distinguish them using either the:
- id or userId (for private find one queries →
{"_id" : <id>}
and private find all queries {userId : <userId>}
)
- id or userId - language (for public find one queries →
{"_id" : <id>}
and public find all queries → {"userId:" "publicUserId", "language" : "en"}
)
I was thinking to embed the languages in the same document as subdocuments, and it works for two types of documents, maybe 3, but then I have other documents where this does not work given the complexity of the document itself. Its not just a single field like name description etc that changes, but these documents have a nested structure and inside that structure I reference other documents and it is exactly here where I need to have the changes for language. Example:
{
_id,
name,
description,
tags,
language,
days: [
{
day: 1,
data: [
{
nb: 0,
subData: [
{
nb: 0,
refDoc1: reference to doc with same language,
name: name of the refDoc1 (as extended reference)
},
{
nb: 1,
refDoc2: reference to doc with same language,
name: name of the refDoc2 (as extended reference)
}]
}]
}]
}
Using your own id is also good, but _id is there by default for every doc…
I would have prefer to use the _id, but then since I have everything in one document I have to use the uniqueId to be able to reference back the documents. For example, I have Document with uniqueId : 1. I have 2 Documents for that uniqueId, one for language “en” and the other for “de”. There are documents that reference one of these two documents, depending on the language, so I will keep the uniqueId and when I have to show the details of the references documents I will do → {uniqueId: 1, language: en}
.
Not sure what you mean by two documents? Collation can be either on a collection or query/operation … If collection level than its default cross collection.
What I mean is, how the collation selects the correct documents? Is it creating a separate collection on its own? Or you have to specify the language on the documents and then the collation selects the correct documents by index?
Thank you
Green