国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Database MongoDB A popular explanation of the concepts of MongoDB databases, collections, and documents

A popular explanation of the concepts of MongoDB databases, collections, and documents

Aug 19, 2020 am 10:27 AM
mongodb

For relational databases, we know that there are multiple tables in the database and multiple rows of data in the data tables. For MongoDB, there are multiple collections in the database, and the collections contain multiple documents.

Database

The database concept of MongoDB is similar to that of Mysql. Each database can set independent permissions.

First, let’s look at how to create a database. MongoDB also has restrictions on database names. Only numbers or letters can be used. In addition, database names are case-sensitive. Generally, we will use lowercase. In addition, some keywords cannot be used, such as: admin, config, local, etc.

In MongoDB, there is no need to create a database explicitly. You only need to select use dbName. When the database does not exist, it will be automatically created for us.

> use huoying
switched to db huoying

When using the db command, the currently used database name will be displayed.

> db
huoying

To view all current databases, use show dbs;

> show dbs;
admin    0.000GB
config   0.000GB
huoying  0.000GB
local    0.000GB

Collection

MongoDB’s collection is similar to the table in Mysql. How many collections are there? consists of documents. But collections do not have field restrictions like tables, and the documents under the collection can be of various types. For example, a collection may have the following two types of documents:

{"name":"gwx", "age" : 30},
{"id":1, "score":100}

Although collections have no restrictions on documents, for the convenience of data management, we generally put related documents in a collection.

Creating a collection is divided into direct creation and implicit creation.

# 顯示的創(chuàng)建集合
> db.createCollection('huoying')
{ "ok" : 1 }

Implicitly create a collection. When creating a document directly, if the collection does not exist, the collection will be created first

Document

Finally, let’s take a look at the documentation. The data type of a document is similar to associated data in PHP or objects in JavaScript.

Note that documents are case and data type sensitive. Look at the following example:

# 下面兩個是不一樣的文檔,他們的數(shù)據(jù)類型不一樣
{"name":30}
{"name":"30"}

# 下面兩個是不一樣的文檔,鍵名不一樣
{"name":30}
{"NAME":30}

New document

Use the command db.collection name.insertOne (document data) to insert into the specified collection A document. If the collection does not exist, it will be created implicitly.

> db.users.insertOne({"name":"gwx", "age":29})
{
 "acknowledged" : true,
 "insertedId" : ObjectId("5f0cfdbb7688816db4d031bc")
}
> db.users.find()
{ "_id" : ObjectId("5f0cfdbb7688816db4d031bc"), "name" : "gwx", "age" : 29 }
>

Modify the document

Use update to update the document content. update requires two parameters. The first one is the qualification. Used to find the specified document, the second is the content of the new document.

> db.users.update({name:"gwx"}, {name:"monkeyking", age:500})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.users.find()
{ "_id" : ObjectId("5f0cfdbb7688816db4d031bc"), "name" : "monkeyking", "age" : 500 }

Delete document

Use remove to delete document

> db.users.remove({age:500})
WriteResult({ "nRemoved" : 1 })

The above is the detailed content of A popular explanation of the concepts of MongoDB databases, collections, and documents. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Apr 18, 2025 am 11:48 AM

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

How to choose a database for GitLab on CentOS How to choose a database for GitLab on CentOS Apr 14, 2025 pm 04:48 PM

GitLab Database Deployment Guide on CentOS System Selecting the right database is a key step in successfully deploying GitLab. GitLab is compatible with a variety of databases, including MySQL, PostgreSQL, and MongoDB. This article will explain in detail how to select and configure these databases. Database selection recommendation MySQL: a widely used relational database management system (RDBMS), with stable performance and suitable for most GitLab deployment scenarios. PostgreSQL: Powerful open source RDBMS, supports complex queries and advanced features, suitable for handling large data sets. MongoDB: Popular NoSQL database, good at handling sea

MongoDB vs. Oracle: Understanding Key Differences MongoDB vs. Oracle: Understanding Key Differences Apr 16, 2025 am 12:01 AM

MongoDB is suitable for handling large-scale unstructured data, and Oracle is suitable for enterprise-level applications that require transaction consistency. 1.MongoDB provides flexibility and high performance, suitable for processing user behavior data. 2. Oracle is known for its stability and powerful functions and is suitable for financial systems. 3.MongoDB uses document models, and Oracle uses relational models. 4.MongoDB is suitable for social media applications, while Oracle is suitable for enterprise-level applications.

MongoDB vs. Oracle: Choosing the Right Database for Your Needs MongoDB vs. Oracle: Choosing the Right Database for Your Needs Apr 22, 2025 am 12:10 AM

MongoDB is suitable for unstructured data and high scalability requirements, while Oracle is suitable for scenarios that require strict data consistency. 1.MongoDB flexibly stores data in different structures, suitable for social media and the Internet of Things. 2. Oracle structured data model ensures data integrity and is suitable for financial transactions. 3.MongoDB scales horizontally through shards, and Oracle scales vertically through RAC. 4.MongoDB has low maintenance costs, while Oracle has high maintenance costs but is fully supported.

What is the CentOS MongoDB backup strategy? What is the CentOS MongoDB backup strategy? Apr 14, 2025 pm 04:51 PM

Detailed explanation of MongoDB efficient backup strategy under CentOS system This article will introduce in detail the various strategies for implementing MongoDB backup on CentOS system to ensure data security and business continuity. We will cover manual backups, timed backups, automated script backups, and backup methods in Docker container environments, and provide best practices for backup file management. Manual backup: Use the mongodump command to perform manual full backup, for example: mongodump-hlocalhost:27017-u username-p password-d database name-o/backup directory This command will export the data and metadata of the specified database to the specified backup directory.

How to set up users in mongodb How to set up users in mongodb Apr 12, 2025 am 08:51 AM

To set up a MongoDB user, follow these steps: 1. Connect to the server and create an administrator user. 2. Create a database to grant users access. 3. Use the createUser command to create a user and specify their role and database access rights. 4. Use the getUsers command to check the created user. 5. Optionally set other permissions or grant users permissions to a specific collection.

How to start mongodb How to start mongodb Apr 12, 2025 am 08:39 AM

To start the MongoDB server: On a Unix system, run the mongod command. On Windows, run the mongod.exe command. Optional: Set the configuration using the --dbpath, --port, --auth, or --replSet options. Use the mongo command to verify that the connection is successful.

How to encrypt data in Debian MongoDB How to encrypt data in Debian MongoDB Apr 12, 2025 pm 08:03 PM

Encrypting MongoDB database on a Debian system requires following the following steps: Step 1: Install MongoDB First, make sure your Debian system has MongoDB installed. If not, please refer to the official MongoDB document for installation: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/Step 2: Generate the encryption key file Create a file containing the encryption key and set the correct permissions: ddif=/dev/urandomof=/etc/mongodb-keyfilebs=512

See all articles