In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
MongoDB concept analysis No matter what database you learn, you should learn the basic concepts. In mongoDB, the basic concepts are document, collection, database SQL terms/concepts. MongoDB terms/concepts explain/explain databasedatabase tablecollection database table/collection rowdocument data record row/document columnfield data field/domain indexindex table joins table join. MongoDB does not support primary key. MongoDB automatically sets the_id field to primary key. Mongodb database Multiple databases can be created 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 collections and permissions, and different databases are placed in different files. 1. Display a list of all data. "show dbs" 2. Displays the current database object or collection. "db" 3. Connect to a specified database. "use Database Name "Note: If the specified database does not exist, it is automatically created. Databases are also identified by name. The database name can be any UTF-8 string that satisfies the following conditions. 1. Cannot be an empty string (""). 2. must not contain ' '(spaces),.,$,/,\ and\0 (empty character). 3. All lower case. 4. 64 bytes maximum. Some database names are reserved, and these databases with special functions can be accessed directly. 1. admin: From a permissions perspective, this is the "root" database. If you add a user to this database, that user automatically inherits permissions from all databases. Certain server-side commands can only be run from this database, such as listing all databases or shutting down servers. 2. Local: This data is never replicated and can be used to store arbitrary collections limited to a single local server. 3. config: When Mongo is used for shard setup, the config database is used internally to store shard related information. A mongodb document is a set of key-value pairs (BSON). MongoDB documents do not need to set the same fields, and the same fields do not need the same data type, which is very different from relational databases, and it is also a very prominent feature of MongoDB. Simple document example: { "c02":"yunjixuan", "name":"cloud computing"} Note: 1. Key/value pairs in documents are ordered. 2. The values in a document can be strings not only enclosed in double quotes, but also several other data types (or even the entire embedded document). 3. MongoDB is type-and case-sensitive. 4. MongoDB documents cannot have duplicate keys. 5. The keys of a document are strings. With a few exceptions, keys can use any UTF-8 character.
Document key naming convention:
Key cannot contain\0 (empty character). This character is used to indicate the end of a key. And $have special meanings and can only be used in certain circumstances. Keys that begin with an underscore "_" are reserved (not strictly required). A collection is a MongoDB document set, similar to tables in an RDBMS (Relational Database Management System). Collections exist in databases, and collections have no fixed structure, which means that you can insert different formats and types of data into collections, but usually the data we insert into collections will have some relevance. You can insert documents with the following different data structures into a collection: {"site":"www.baidu.com"}{"site":"www.google.com","name":"Google"} When the first document is inserted, the collection is created.
Collection name of law:
Collection name cannot be empty string "". Collection names cannot contain the\0 character (null), which indicates the end of the collection name. Collection names cannot begin with "system. ", which is a prefix reserved for system collections. User-created collection names cannot contain reserved characters. Some drivers do support inclusion in collection names because some system-generated collections include this character. Unless you want to access collections created by such systems, do not include $in the name. 5. The information in the metadata database is stored in collections. They use the system namespace: dbname.system.* In MongoDB namespace.system.* is a special collection containing a variety of system information, as follows: Collection namespace description dbname.system.namespaces Lists all namespaces. dbname.system. indexesLists all indexes. dbname.system.profile Contains database profile information. dbname.system.users Lists all users who have access to the database. dbname.local.sources Contains server information and status for replication slaves. VI. MongoDB data type data type description String character string. Common data types for storing data. In MongoDB, UTF-8 encoded strings are legal. Integer integer value. Used to store values. Depending on which server you are using, it can be 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 compares a value to the lowest and highest values of a BSON (binary JSON) element. Array is used to store arrays or lists or multiple values as a key. Timestamp. Record the exact time the document was modified or added. Object is used for inline documents. Null is used to create a null symbol. This data type is basically identical to the string type, but differs in that it is generally used for languages that use special symbol types. 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 date, month, and day information. Object ID Object ID. ID used to create the document. Binary Data Binary Data. Used to store binary data. Code Type. Used to store JavaScript code in documents. Regular expression Regular expression type. Used to store regular expressions. mongodb standard URI connection syntax: mongodb://[username:password@] host1 [:port1][, host2 [:port2],... [,hostN[:portN]]][/[database][? options]]
Description:
mongodb://This is a fixed format and must be specified. username:password@ Optional, if set, the driver will try to log in to the database after connecting to the database server. host1 must specify at least one host, host1 is the only one to be filled in for this URI. It specifies the address of the server to connect to. Specify multiple host addresses if you want to connect replication sets. portX Optional specified port, if left blank, defaults to 27017/database If username:password@ is specified, connect and verify login to the specified database. If not specified, the test database is opened by default. options are connection options. If you do not use/database, you need to add/before it. All join options are key-value pairs name=value, separated by∨(semicolon) The standard join format contains multiple options, as follows: Option description replicaSet=name Verify the name of the replica set. Impliesconnect=replicaSet.slaveOk=true false1. true: In connect=direct mode, the driver connects to the first machine, even if that server is not the master. In connect=replicaSet mode, the driver sends all write requests to the master and distributes reads to other slaves. 2.false: In connect=direct mode, the driver will automatically find the master server. In connect=replicaSet mode, the driver connects only to the primary server, and all read and write commands are connected to the primary server. w= nDrive Add { w : n } to getLastError command. Apply to safe=true. wtimeout MS =ms write timeout, driver adds { wtimeout : ms } to getlasteror command. Apply to safe=true.fsync=true false1. true: Driver adds { fsync : true } to getlastererror command. Apply to safe=true. 2. false: Drivers are not added to getLastError command. journal=true false If set to true, synchronize to journal (write to entity before committing to database). Apply to safe=trueconnectTimeoutMS=ms The time a connection can be opened. Connection timeout socketTimeoutMS=ms Time to send and receive sockets. mongodb Connection Command Format: To connect to the MongoDB server using a username and password, you must use the format 'username:password@hostname/dbname', where'username'is the username and'password'is the password. Connect to the local MongoDB server using password 123456 as user admin: mongodb://admin:123456@localhost/Connect to the specified database using user name and password: mongodb://admin:123456@localhost/test Connect to replica set Three servers (ports 27017, 27018, and 27019):mongodb://localhost,localhost:27019 Connect to replica set Three servers, write operations apply to the master server and distribute queries to the slave servers. mongodb://host1,host2,host3/? slaveOk=true Connect directly to the first server, whether it is part of a replica set or a master or slave server. mongodb://host1,host2,host3/? connect=direct;slaveOk=true Safe mode Connect to localhost:mongodb://localhost/? safe=true Connect to replica set in safe mode and wait for at least two replication servers to write successfully, timeout set to 2 seconds. mongodb://host1,host2,host3/? safe=true;w=2;wtimeoutMS=2000
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.