In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "what are the basic concepts of MongoDB database?", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what are the basic concepts of MongoDB database" article.
The following table will help you understand some of the concepts in MongoDB more easily:
SQL terminology / concept MongoDB terminology / concept explanation / description databasedatabaee database tablecollection database table / collection rowdocument data record row / document columnfield data field / domain indexindex index table joins table join, MongoDB does not support primary keyprimary key primary key, MongoDB automatically sets _ id field to primary key 1, database
Multiple databases can be set up in a MongoDB.
The default database for MongoDB is "db", which is stored in the data directory.
A single instance of MongoDB can hold multiple independent databases, each with its own collection and permissions, and different databases are placed in different files.
1. Use the "show dbs" command to display a list of all databases, as shown in the following figure:
2. Execute the "db" command to display the current database object or collection, as shown in the following figure:
3. Execute the "use" command to connect to a specified database.
For example, switch from the current test database to the local database, as shown in the following figure:
Admin: from a permission perspective, this is the "root" database. If you add a user to this database, the user automatically inherits the permissions of all databases. Some specific server-side commands can only be run from this database, such as listing all databases or shutting down the server.
Local: this data is never replicated and can be used to store any collection limited to a single local server.
Config: when MongoDB is used for sharding settings, the config database is used internally to store information about sharding.
II. Documentation
A document is a set of key-value pairs (that is, BSON). MongoDB documents do not need to set the same fields, and the same fields do not need the same data type. This is very different from the relational database, and it is also a very prominent feature of MongoDB.
An example of a simple document is as follows:
{"site": "www.baidu.com", "name": "Baidu"}
Terms for RDBMS and MongoDB:
It is important to note that:
1. The key / value pairs in the document are ordered.
2. The value in the document can be not only a string in double quotes, but also several other data types (or even the entire embedded document).
3. MongoDB is case sensitive and type sensitive.
4. MongoDB documents cannot have duplicate keys.
5. The key of the document is a string. With a few exceptions, keys can use any UTF-8 character.
Document key naming convention:
1. The key cannot contain\ 0 (empty character). This character is used to indicate the end of the key.
2 、. And $have special meaning and can only be used in specific circumstances.
3. The key at the beginning of the underscore "_" is reserved (not strictly required).
III. Collection
Collections are MongoDB document groups, similar to tables in RDBMS (that is, relational database management systems).
The collection exists in the database, and the collection has no fixed structure, which means that you can insert different formats and types of data into the collection, but usually the data we insert into the collection will have certain relevance.
For example, we can insert documents with the following different data structures into the collection:
{"site": "www.baiduc.com"}
{"site": "www.baiduc.com", "name": "Baidu"}
{"site": "www.baiduc.com", "name": "Baidu", "address": "Beijing"}
Legal collection naming
1. The collection name cannot be an empty string "".
2. The collection name cannot contain the\ 0 character (empty character), which represents the end of the collection name.
3. The collection name cannot start with "system", which is the prefix reserved for the system collection.
4. User-created collection names cannot contain reserved characters. Some drivers do support inclusion in the collection name because some system-generated collections contain this character. Do not include $in the name of the collection unless you want to access the collection created by the system.
MongoDB data type
Data type
Description
String
String. Data types commonly used to store data. In MongoDB, a string encoded by UTF-8 is legal.
Integer
Integer value. Used to store numeric values. According to the server you use, it can be divided into 32-bit or 64-bit.
Boolean
Boolean value. Used to store Boolean values (true / false).
Double
Double precision floating point value. Used to store floating-point values.
Min/Max keys
Compare a value with the lowest and highest values of the BSON (binary JSON) element.
Arrays
Used to store an array or list or multiple values as a key.
Timestamp
Time stamp. Record when the document was modified or added.
Object
Used to embed documents.
Null
Used to create a null value.
Symbol
Symbols. This data type is basically equivalent to a string type, but it is generally used in languages with special symbolic types.
Object ID
Object ID. The ID used to create the document. Automatically created by default when you create a document
Binary Data
Binary data. Used to store binary data.
Code
Code type. Used to store JavaScript code in a document.
Regular expression
Regular expression type. Used to store regular expressions.
Date
Date, time. Stores the current date or time in UNIX time format. You can specify your own date and time: create a Date object and pass in the year, month and day information.
The above is the content of this article on "what are the basic concepts of MongoDB database". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.