undefinedfix
Sign in

What does mongodb document storage mean?

Mohyt edited in Fri, 03 Jun 2022

Mongodb is the storage method of key value. Like redis, their value supports multiple data types. How to understand the document storage of mongodb? Does it mean that it can directly store word documents, Excel and pictures? Unlike mysql, it stores their paths. After a brief introduction to mongodb and redis, I feel that what mongodb can do, redis can do the same. Why choose mongodb for some scenes. For example, you need to display data in real time. You can do both.

I don't understand them thoroughly enough.

2 Replies
thabouti
commented on Fri, 03 Jun 2022

Don't think it's that complicated. Take storing an article as an example. The article has fields:

  1. title
  2. content
  3. picture
  4. time

When using relational data storage, you may create an article table, and then create corresponding fields to store corresponding data. Mongodb directly stores the fields and corresponding contents as a JSON (the following JSON).

{
    "title":"文章标题",
    "content":"文章内容",
    "img":"文章图片",
    "createTime":"创建时间"
}

Based on the two methods in, you will see that if it is a relational database, if you want to add or delete a field, you may have to consider a lot of things. But for mongodb, it's very convenient to add the corresponding fields and contents in JSON directly.

sq8l
commented on Fri, 03 Jun 2022

Some superficial understanding

Document storage is generally stored in a format similar to JSON, and the stored content is document type. In this way, we have the opportunity to index some fields and realize some functions of relational database.

Mongodb is between relational database and non relational database. Each record is a document (corresponding to row of relational database), and a group of documents form a document group (corresponding to table), which can index some fields of the document. It can support rich query language just like relational database.

Redis is a non relational database. Hash supports simple relationships and fast key value reading, but it does not support complex relationships and field index, so it is not suitable for query and search.

lock This question has been locked and the reply function has been disabled.