"Mongodb and mongomapper are powerful database tools often used

I am currently working on a Rails app that uses ActiveRecord to manage products. Each product has a category and subcategory, with each subcategory defined by multiple fields within the application. This system has become quite complex and I have been considering using MongoDB and Mongomapper from the start instead.

My main question is how best to model this application in MongoDB. I was thinking of creating a product model with common fields and then having category models inherit from the product model with different unique fields.

Another challenge I am facing is allowing users to create their own categories and fields within the application. For example, if a user creates a "cars" category with fields like speed and number of doors, how can I dynamically generate a form using these new fields for future car entries?

If anyone has any ideas, pointers, or examples to help me with this problem, I would greatly appreciate it.

Thank you in advance, Rick

Answer №1

Although I am not well-versed in Ruby/Mongomapper, I can provide some insights on how the data should be structured in Mongo from a high-level perspective.

Collection: Category

{"_id" : "car"}
{"_id" : "vintage_car", "parent" : "car", "fields" : ["year" : "integer", "original_parts" : "boolean", "upgrades" : "text"] }

Collection: Products

{"_id" : "1234", "name" : "Model-T", "category" : "car", "sub-category" : "vintage_car", "values" : ["year" : 1942, "original_parts" : false, "upgrades : "XM Radio"] }

The structure is relatively straightforward. The Categories and Sub-categories are stored in one collection, with Sub-categories having a "parent" field set to distinguish them from main Categories.

Each Sub-category has defined fields under "fields," allowing for easy rendering of input boxes based on the type specified (e.g., "integer" or "boolean"). You can customize this further by adding different types like "datepicker" or "checkbox."

Products reference both Category and Sub-category, along with values for the associated fields, making it simple to render product information dynamically.

EDIT

In response to a comment, units of measure can be included in the Category's "fields":

..."fields" : [{"length","meters","float"},{"weight","kg","float"},...]

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

The global installation of grunt was unsuccessful and I am unable to locate it on npmjs.org

Can anyone help me troubleshoot this error I'm encountering while running npm install? I usually don't have issues installing libraries globally, but I can't seem to find grunt on npm install -g grunt npm ERR! Error: Not found: grunt@&apos ...

Issues with retrieving data from Firestore and storing it into an array in a React

Struggling to fetch data from my firestore and display it on the webpage. Despite trying all possible solutions and searching extensively, I am unable to get it working. When using the code below, nothing appears on the website. However, if I switch to th ...

Altering URL while transmitting file via Express

When attempting to send an HTML file as a response, I am experiencing an issue where the current URL is being maintained. Despite my attempts to use the location method, it does not seem to work. Ideally, I would like the functionality to redirect to a new ...

How can jQuery identify a specific combination of letters and single-digit numbers?

I am working with the following HTML elements <button id="btn7">7</button> <button id="btn8">8</button> <button id="btn9">9</button><button id="btnMulti">*</button> ...

The GLTFLoader does not support the replacement of its default materials

I am currently working on a scene that includes: AmbientLight color: light blue PointLight color: pink a gltf object loaded with textures Using the GLTFLoader, I successfully loaded a gltf object with texture map. The model is displayed correctly with ...

Updating JSON data in real time using JavaScript by manipulating MySQL database entries

My database has a mysql structure consisting of the columns ID, NAME, and TYPE. The data is then converted into a JSON format as shown below: [ {id: "1", name: "Snatch", type: "crime"}, {id: "2", name: "Witches of Eastwick", type: "comedy"}, { ...

Using the preselection feature in the MUI DataGrid can cause the grid to become disabled

I am customizing a mui datagrid to have preselected rows using the following code snippet: const movieCrewList = movieCrew.map((item) => item.id); const [selecteTabledData, setSelectedTableData] = React.useState([]); <DataGrid rows={crewData} c ...

Showing outcomes from various API requests

I have encountered an issue while making two API calls to a backend server and trying to display both responses in JSON format to the user. Strangely, alert 2 is showing as 'undefined' when I check the console, while alert 1 works perfectly fine. ...

There seems to be an issue with the location.href function in the server-side code of

I'm encountering an issue in the code below where I am attempting to redirect to the login page, but it seems to not be functioning as expected. app.get('/current-pass', (req, res) => { res.sendFile(path.join(staticPath, "currentPass ...

Using React.js - What is the process for submitting a form automatically when the page loads?

Upon loading the page, I have a form that needs to be displayed. Here is the code snippet: <form name="myform" method="POST" className={classes.root} target="mydiv" action="https://example.com/submit" onLoad= ...

Unlock the innerHTML of a DIV by clicking a button with ng-click in Angular JS

I am curious about something. There is a <div> and a <button> in my code. I am looking to access the inner markup of the <div> within the ng-click function without relying on jQuery. Can you give me some guidance? <div id = text-entry ...

execute node.js scripts through a gulp task

I'm looking for a way to run multiple JavaScript scripts located in the same folder (scripts/*.js) using a gulp task, instead of having to manually execute each script with 'node script.js' individually. Can anyone help me achieve this? May ...

Output each element of an array in Vuejs2 with a line break between each

I am currently working with vuejs2 and have a select tag where a person is selected, with their address properties directly bound to the element. I need to display the address of the selected person. I attempted to use an array in order to print out the el ...

The form fails to submit even after the validation process is completed

My current dilemma involves the validation of an email and checkbox to ensure they are not empty. Although it initially seemed to work, after filling in the required fields and checking the box, I still receive a warning message (.error) and the form fails ...

Verify if the video has finished loading and then pass it to the parent component with a value of null

In an attempt to check if a video has successfully loaded and can play in the child component (LandingComponent), I want the parent Component (App) to update 'loaded' as true, remove the spinner (SpinnerComponent), and display the full webpage. ...

Java implementation of a Least Recently Used (LRU) eviction policy for MongoDB

As a newcomer to mongoDB, I am currently developing an application that necessitates the implementation of an LRU policy on my collection. Upon researching on the mongoDB site, I found that capped collections only support FIFO. Are there any other types of ...

Encountering a CORS issue when utilizing Stripe with various servers while navigating with a Router

I have a router that utilizes Router.express(). The backend operates on port 5000, while the frontend runs on port 3000. Within the frontend folder, there is a button with a fetch request (http://localhost:5000/create-checkout-session). In the backend, the ...

Challenge encountered in Ajax with data processing

Help needed with making an ajax request to update the "status" parameter of my "task" object. The script is set up to retrieve the task ID and the new status, but I'm encountering errors in either the routes.rb file, the update_status function within ...

Enhancing Numbers with JavaScript

What I'm Looking for: I have 5 counters on my webpage, each starting at 0 and counting upwards to different set values at varying speeds. For example, if I input the values of 10, 25, 1500, 400, and 500 in my variables, I want all counters to reach t ...

Auto Suggest: How can I display all the attributes from a JSON object in the options list using material-ui (@mui) and emphasize the corresponding text in the selected option?

Currently, I am facing a requirement where I need to display both the name and email address in the options list. However, at the moment, I am only able to render one parameter. How can I modify my code to render all the options with both name and email? ...