Designing object schema for MongoDB metadata

Please forgive my lack of knowledge in computer terminology:

In my Mongo app, I aim to establish a defined structure for each document type. This structure will include constraints, validation patterns, and access roles for viewing, modifying, and deleting the document.

For instance, let's take a Book:

{
 name: "Book",
 viewRoles: ["Admin","User"],
 createRoles: ["Admin"],
 modifyRoles: ["Admin", "User"],
 fields: [
 {
    id:"title",
    name:"Book Title",
    validation: "",
    maxLength: 50,
    minLength: 3,
    required: true
   },
   {
    id:"authorEmail",
    name:"Email of the Author",
    validation: "email",
    maxLength: 50,
    minLength: 3,
    required: false
   }
 ]
}

By applying this 'schema' to all documents, I can have a unified interface for creating, modifying, and displaying these 'entities'.

Furthermore, I wish to enable the creation of new document types and the ability to adjust their fields via the admin panel of my application.

Searching for terms like "mongo dynamic schema" or "mongo document meta design" yields unhelpful results.

My inquiry is about the terminology used when implementing a predefined schema for documents with the option to modify it. Where can I find more information on designing such systems?

Answer №1

Hey there! Since you mentioned a Meteor connection, I wanted to share with you about Simple Schema: https://github.com/aldeed/meteor-simple-schema/. It's a tool that I personally use in combination with collection2 package. I've found it really helpful for documenting and enforcing schema design. Plus, when paired with the autoform package, it allows you to easily create validated forms based on your schema.

Answer №2

If you're seeking guidance on data modeling, check out this helpful link:

http://docs.mongodb.org/manual/data-modeling/

Additionally, I am interested in the ability to create new document types and modify their fields through my application's admin panel.

For administrative tasks, explore the options provided here:

http://docs.mongodb.org/ecosystem/tools/administration-interfaces/

Once you've completed these steps, it may be beneficial to read up on MongoDB schema design pitfalls:

In Mongo DB, collections are not created in advance. They are generated when you insert data for the first time. Ensure to index your collection before adding documents:

db.collection.ensureIndex({keyField: 1})

The key is maintaining document structure rather than predefining the collection in MongoDB.

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

Prioritizing tasks, always giving a call once they are completed

I am trying to populate an HTML snippet with data from Firebase. Here is the JavaScript code I wrote to achieve this: members.forEach(el => { console.log(el) table_number++; console.log("forEachMember" + table ...

Error message: The attempt to convert the value ":listId" to an ObjectId for the model "Task" failed at the path "_listId"

I am encountering the casterror in my mongoose. I apologize for raising this question again, but I am struggling to identify my error. While I can see the results using Postman, I am unable to display the tasks on my frontend. I am facing difficulty in fet ...

What is the method for determining the dimensions of a cube?

Currently, I am working with a cube geometry and a mesh in my project. However, I am facing a challenge figuring out how to obtain the width of the cube. Below is the snippet of code that I am struggling with: geometry = new THREE.CubeGeometry( 200, 200 ...

Flattening the path during deserialization in Rust's Serde library

I need to convert a complex JSON data structure into a Rust struct: { "root": { "f1": { "f2": { "f3": 123 } } } } When using Deserialize, I find myself creating multiple nested struc ...

Performance comparison between static and dynamic interpolation techniques in Angular.js

Could you explain the discrepancies between: A: {{ variable | filter }} and B: {{ 'static string' | filter }} I have a few questions regarding this: Are both considered interpolations or just A? Does A utilize $interpolate, while B utilizes ...

Utilize AngularJS to Capitalize the First Letter and the Letter Following a Dot (.)

I am seeking a solution to capitalize the first letter in a given string, like so: sumo => Sumo Additionally, I need to capitalize strings in the following format: Dr.ravi kumar => Dr.Ravi kumar Although I have implemented an Angular filter that ...

Unable to insert multiple post requests into the Mongo database at once

I am currently using MongoDB to retrieve and submit data, but I seem to encounter an issue when attempting to submit more than one request. Even when using different values for the second submission, I still face the same error. I am having trouble identif ...

Command for kicking initiated, tag unreadable

I'm currently working on adding a new command to my bot, but I can't seem to figure out why the 'tag' property is showing as undefined. While ${user.tag} works perfectly fine in my real kick command, it fails to recognize the user who s ...

Transform an object into an array using JavaScript with the help of Lodash, Azure Functions, and Azure Logic Apps

To achieve the desired result of extracting JSON from a proprietary content management system, transforming it into a CSV, and depositing that CSV in an Office 365 shared drive, a combination of Azure Function and Azure Logic App is utilized. The Node/Java ...

Obtain the predecessor of the element that was clicked

I have a complex structure with nested tables, rows, and cells, each containing div elements with multiple spans. I am trying to create a function that will capture the clicked cell every time I click on either the cell itself or any of its child elements ...

Meteor: Uncaught ReferenceError: require is undefined

After installing meteorhacks:npm and defining apn in packages.json as {"apn": "1.6.2"}, I encountered an error message stating ReferenceError: require is not defined when trying to execute the following code: var apn = Npm.require('apn'), pa ...

Creating a Conditional "Retrieve Script File" Function in JavaScript Without Dependencies

At the company where I work, we have numerous clients with their own websites that are connected to our system through a linking mechanism. Essentially, these clients have a link on their website that directs users to our site upon clicking. I am working ...

How to convert DateTime to UTC in TypeScript/JavaScript while preserving the original date and time

Consider the following example: var testDate = new Date("2021-05-17T00:00:00"); // this represents local date and time I am looking to convert this given Date into UTC format without altering the original date and time value. Essentially, 2021-0 ...

Exploring Heroes in Angular 2: Retrieving Object Information by Clicking on <li> Items

Currently, I am delving into the documentation for an angular 4 project called "Tour of Heroes" which can be found at https://angular.io/docs/ts/latest/tutorial/toh-pt2.html. <li *ngFor="let hero of heroes" (click)="onSelect(hero)">{{hero.name}}< ...

Creating Typescript libraries with bidirectional peer dependencies: A complete guide

One of my libraries is responsible for handling requests, while the other takes care of logging. Both libraries need configuration input from the client, and they are always used together. The request library makes calls to the logging library in various ...

Uploading files with Multer and handling the JSON object

Is there a way to send both a file and a JSON object containing data using multer? I came across this thread, but it only explains how to attach one field at a time. Here's what I currently have on the client side: request .post(uploadPOSTUrl) . ...

Exploring the power of regular expressions in Javascript

In my code, I am using the following regular expression: var re = new RegExp("(^|\\s)" + classname + "(\\s|$)"); I know that \s represents a white-space character and the caret symbol denotes the "beginning with". However, I am c ...

When running tests in Jest, the error "TypeError: _enzymeAdapterReact.default is not a constructor

I'm encountering an issue while testing a react-native component with jest and enzyme TypeError: _enzymeAdapterReact.default is not a constructor Below are my development dependencies: "@babel/core": "^7.12.10", "@ba ...

JavaScript Logic to Check if an Element is Hidden

I'm having trouble figuring out how to close an element when another element collapses. I've searched for solutions without success. My structure is updated using Bootstrap and JavaScript, but it doesn't function as expected. Specifically, ...

Setting a key in an object on-the-fly

Building a dynamic query for MongoDB using Node.js is proving to be a challenge for me. Here is the function responsible for creating it: app.set('searchTerm', function (field, str){ var i, searchTerm, keywords; keywords = st ...