Skip to main content

Document embedding


Intro

Koxy Database supports a feature called document embedding, which allows you to add relationships to documents. This means that you can store related data in the same document, which can make it easier to query and manage your data.

For example, you could have a document that represents a user in the users collection. This document could contain the user's name, email address, and other personal information. You could also embed a list of the user's friends in the same document. This would make it easy to query for all of the friends of a particular user.

Document embedding is a powerful feature that can help you to better organize and manage your data. It is a great way to improve the performance of your queries and to make it easier to find the data that you need.


How to use Document embedding

First We recommend to check What are documents.

Let's setup the example We talked about above, our document's data should be something like this:

{
"name": "kais",
"email": "kais@email.com",
"avatar": null,
"friends": "koxy.data.{collection_id.document_id}"
}
  • the collection_id is the ID of the collection to get the document from.

  • the document_id is the ID of the document to get.

You can also get specefic data from another document using dot notation like this:

{
"name": "kais",
"email": "kais@email.com",
"avatar": null,
"friends": "koxy.data.{collection_id.document_id}",
"friend1_name": "koxy.data.{collection_id.document_id.friend1.name}"
}

All the data is live synced across collections.

Costs

Every relational document you load will cost you a cloud run the same as any other read operation.