MongoDB

Some Examples of MongoDB Documents

This article demonstrates Some Examples of MongoDB Documents. Since MongoDB is not a relational database system, a MongoDB database doesn’t have tables with rows and columns as usual. Rather, a MongoDB database contains collections. Further, a collection comprises of documents.

The following list provides Some Examples of MongoDB Documents.

At first, consider the following User Document that we can create in MongoDB. As can be seen, there is a unique Object Id. To illustrate, the document has features like name, email, age, address, and interests. However, address attribute is composite. Because it comprises of three attributes -street, city, and state.

{
    "_id": ObjectId("5f9d80f0efa12e085f5e5b5c"),
    "name": "John Doe",
    "email": "johndoe@example.com",
    "age": 30,
    "address": {
        "street": "1 Main St",
        "city": "New York",
        "state": "NY"
    },
    "interests": ["reading", "traveling", "music"]
}

Another example is a Blog Post Document. Likewise, it has a unique Object Id. Meanwhile, it has attributes like title, author, content, date_published, and tags. Take the case of tags attribute. Its type is array. In order to read more on MongoDB attribute types, click here.

{
    "_id": ObjectId("5f9d819aefa12e085f5e5b5d"),
    "title": "How to Write a Blog Post",
    "author": "Jane Doe",
    "content": "In this blog post, we will discuss the steps involved in writing a blog post...",
    "date_published": ISODate("2022-12-01T09:30:00.000Z"),
    "tags": ["blogging", "writing", "tips"]
}

Another example is a Product Document. In the similar way, it has a unique Object Id. Among other attributes, there name, manufacturer, price, release_date, and ratings. Furthermore, ratings is an array type attribute. Moreover, it is a composite attribute.

{
    "_id": ObjectId("5f9d825aefa12e085f5e5b5e"),
    "name": "Apple iPhone X",
    "manufacturer": "Apple Inc.",
    "price": 999.99,
    "release_date": ISODate("2017-11-03T00:00:00.000Z"),
    "ratings": [
        {
            "user": "John Doe",
            "rating": 4.5,
            "review": "Good product with great features"
        },
        {
            "user": "Jane Doe",
            "rating": 4.0,
            "review": "Nice phone with a good camera"
        }
    ]
}

These are just examples and the structure of the documents in a MongoDB collection can vary depending on the requirements of your application. In fact, MongoDB has a wide range of applications. The following list provides some of the applications.

  1. Content Management System
  2. E-Commerce Applications
  3. Business Intelligence
  4. Analytics
  5. Gaming applications

In general, these are just a few examples, and MongoDB’s wide range of features and scalability make it a suitable choice for many other types of applications as well.

Useful Links

What is MERN Stack?

Features of MERN Stack

Alternatives of MERN Stack


Further Reading

Attribute Types in MongoDB

Overview of Mean Stack

Creating Single Page Applications with Angular

Angular 10 Data Binding in Different Ways

Creating Some Angular Components

Examples of Array Functions in PHP

Basic Programs in PHP

princites.com


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *