Using a JSON database to implement various user levels in a domain model

Here is the domain model that I believe to be accurate. I am currently attempting to implement this on a JSON database, but I am uncertain if I am headed in the right direction. From my understanding of JSON, there are no inherent relationships between objects - how can I establish connections between them?

The model includes two types of users: one with a single vehicle and driver, and another type of user who is a manager with multiple vehicles and drivers.

I would greatly appreciate any feedback on whether I am approaching this correctly.

My platform of choice is Firebase, meaning I must work exclusively with JSON format.

Answer №1

When transitioning to a document-based or object-oriented database from a relational one, the concept of relations is replaced by associations (where you might also want to explore aggregation):

  • A 1-1 association can be seen as a property that links to the other entity in the association. For example, a customer has a profile and a profile is linked to a customer.
  • A 1-n association is shown through a collection, often represented as an array in JSON. For instance, an order contains multiple order lines.
  • An m-n association utilizes collections on both sides for the connected objects. For instance, multiple authors write many questions.

It's important to note that following this methodology could lead to having a single aggregate root (the main object in your model), which may not be optimal due to nesting limitations in most NoSQL databases.

Therefore, it's recommended to separate objects that can exist independently into their own collections (similar to tables in the relational world), while objects always associated with others should not have their standalone collections. For example:

  • A customer might have its individual collection.
  • An order line is dependent on an order and doesn't need its own collection. You wouldn't typically query all order lines across orders simultaneously...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

For the past 8 hours, my main focus has been on successfully transmitting a basic JSON object containing data from an API from my Express backend to a React component

I have been trying to achieve my initial goal of retrieving data from the API I am using on the backend, inserting that data into my database, and then sending that data through res.json so it can be accessed on the frontend via fetch. Despite all my attem ...

How to display JSON data in a table using UI5

I am encountering an issue while trying to display JSON data in UI5. I have successfully loaded the data and can access it to show in individual fields, such as a text view. However, I am facing problems when attempting to display the data in a table. Her ...

What is the most effective way to perform two GET requests in PHP?

Here's the code snippet I am currently working on: $header = [ 'phoneType' => $mobileType ]; \Drupal::logger("cam")->debug('PageNameHere retrieveAPINameHere REQUEST: '.json_encode($head ...

How to generate a custom JSON key name in PHP using Laravel

Currently, I am utilizing imagick to extract a number of pages and then store it in JSON format. However, the number is stored as is without any key, for instance - 20. I am seeking a way to store the number with a specific key like below: { "pages": " ...

Transform keys and values into distinct arrays with a sudden surge of energy

Upon examining a nested JSON structure, I need to extract keys and values into two separate arrays as shown in the desired output. Here is the input: { "ms": [ { "ts": "2024-02-13T12:43:00.000Z", "ls& ...

Trouble with using AJAX to transfer a JavaScript variable to a PHP file

I need assistance in sending a JavaScript variable to a PHP file for displaying comments on a webpage. While I have successfully sent the JS variable to other PHP files, I'm facing issues when trying to do the same with the comment-list.php file. It ...

What is the best way to structure my JSON data?

Below is an example of JSON data: [ {"name":"userID","value":"123"}, {"name":"score","value":"95"}, {"name":"dob","value":"20-Feb-1990"}, {"name":"location","value":"New York"} ] I am looking to transform this JSON into: { "userID":"123", "s ...

Counting JSON elements with PostgreSQL

I am facing an issue with a JSON type column named "log_data" that stores data in the following format [{"key":"test123123","identity":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7d2d4c2d5e7d3c2d4d389ced3">[email p ...

Creating dynamic forms using AngularJS with a click event for the action button

I am looking to dynamically generate form fields based on the JSON structure. Currently, I have successfully rendered the fields on the webpage using a JavaScript file. However, I need assistance in adding action items to the "button" part. For example, I ...

Tips for utilizing the ng-filter Json [@attributes] with Angularjs

I'm trying to sort through sports feed based on sport ID, but the JSON feeds are structured with @attributes. JSON Feeds series: [ { @attributes: { id: "cdf590b4-0206-45b0-9122-20eae46a2b27", name: "Pakistan tour of Sri Lanka, 2015", year ...

Adding a JSON array to a ListView

I am new to Java programming language, so please forgive any obvious or silly mistakes I may have made. I am working on an activity in which I retrieve a JSON encoded string from a PHP file and display it in a simple list view. However, I am encountering ...

Receive various JSON replies from PHP

I am currently developing an app using PhoneGap which involves a script to read a ticket code. The script performs two queries: one to update the ticket status in the database if it exists, and another to write a log in a separate table. This functionality ...

How to convert a nested array of objects into a string using JavaScript for passing as a URL parameter

So, I'm dealing with a nested JSON array of objects here. My goal is to pass it as a parameter in the URL and then save it to my MongoDB database. However, when I tried doing that, it ended up being saved as [object object]. Does anyone know how to so ...

Guide to sending an Array of objects in the request body using RestAssured in Java

Here is the Request I am working with: [ { "userId": "value1" },{ "userId": "value2" } ] I attempted to create a POJO class and construct the request, as well as using an ArrayList, but there ...

The art of handling exceptions in Django and delivering personalized error messages

In contemplating appropriate exception handling for my Django app, I am focused on ensuring the utmost user-friendliness. User-friendliness in this context means providing detailed explanations to users when errors occur. As mentioned in a helpful post, ...

Jackson can convert property fields starting with "property_" into a list during deserialization

My task involves serializing an object class: public class DigitalInput { private String id; private Date timestamp; private String matter; private String comment; private String channelId; private List<IndexableProperty> o ...

Read and insert an object into another object without using an array

I am currently attempting to verify and add an object within another object's details from a JSON file. Here is what my JSON structure looks like: { "stylesheet": { "attribute-set": [ { "attribute": [ { "_na ...

Sharing JSON data between PHP and JavaScript/AJAX

In order to validate strings on my website, I am developing a validation mechanism using both Javascript and ajax for client-side validation and PHP for server-side validation. It is essential for both PHP and Javascript to utilize the same variables, suc ...

Put JSON data into SQL database table

I have the SQL Table 1 shown below: id name gender age country ambition 1 Peter Male 20 Italy Doctor 2 Angeli Female 30 Australia Lawyer I need to insert data into another table using a similar approach. Here is how I want the output in SQL Tabl ...

Providing status after saving data to multiple databases in a single API request

I've primarily focused on frontend development, but recently I've ventured into backend development with Node.js and Mongoose. My current project involves creating a user in the database, generating an email token, and sending an email all within ...