Basic knowledge for getting started with mongoDB

Source: Internet
Author: User
MongoDB is an open-source, high-performance, non-mode (or free mode) Documentation-oriented database written in C ++. Because MongoDB is document-oriented, it can manage a collection of documents similar to JSON. Because the data can be nested into a complex system and can be queried and indexed, the application can

MongoDB is an open-source, high-performance, non-mode (or free mode) Documentation-oriented database written in C ++. Because MongoDB is document-oriented, it can manage a collection of documents similar to JSON. Because the data can be nested into a complex system and can be queried and indexed, the application can

MongoDB is an open-source, high-performance, non-mode (or free mode) Documentation-oriented database written in C ++. Because MongoDB is document-oriented, it can manage a collection of documents similar to JSON. Because data can be nested into a complex system and can be queried and indexed, applications can model data in a more natural way.

The following describes the features of MongoDB:

  1. Unified UTF-8 encoding: data that is not a set of UTF-8 encoding can also be saved and queried by using a special binary data type.
  2. Cross-platform support: binary files can be used on Windows, Linux, OS X, and Solaris platforms. MongoDB can be compiled on most small-end systems.
  3. Supports multiple types: dates, regular expressions, code, binary data, and so on.
  4. The query result supports the Cursor operation.
  5. Supports Ad hoc queries (Ad hoc query: Ad hoc query, which is the most common query for database applications. With the data warehouse technology, users can obtain desired data from the database at any time. In MongoDB, You can query any field at any time. It supports range queries, regular expression searches, and other special query types. The query can also contain user-defined javascript Functions.
  6. Supports query of nested domains: the query can go deep into nested objects and arrays if the following objects are inserted into the users set.
  7. {"username" : "bob","address" : {"street" : "123 Main Street","city" : "Springfield","state" : "NY"}}

    We can query the nested domain db. users. find ({"address. state": "NY "})

    The array element can be queried as follows:> db. food. insert ({"fruit": ["peach", "plum", "pear"]}) or> db. food. find ({"fruit": "pear "})

  8. Supported indexes: Secondary indexes include single-key, compound, unique, non-unique, and geospatial indexes. nested fields can also be indexed. If we index an array, all elements in the array will be indexed automatically. When a query is executed, the MongoDB query optimizer tries multiple different query plans and selects the fastest execution speed. You can use the explain function to view the index usage process, and then use the hint function to select another index. You can create and delete indexes at any time.
  9. Aggregation: In addition to ad hoc queries, MongoDB also supports a series of tools to support aggregation, such as MapReduce and other group by function sets similar to SQL.
  10. File Storage: The software implements a protocol called GridFS, which is used to store and retrieve files from the database.
  11. Supports server-side javascript Execution: javaScript is a common language of MongoDB. It can be used for queries and Aggregate functions and is directly executed by the database.
  12. The following is an example of a query using javascript: db. foo. find ({$ where: function () {return this. x = this. y ;}})

    Send code to the database for execution: db. eval (function (name) {return "Hello," + name ;}, ["Joe"])

    JavaScript variables can be stored in the database and used by other javas as global variables. Any valid javascript types, including functions and objects, can be stored in MongoDB, so javascript can be used to write <存储过程>

  13. Capped collection: MongoDB supports a set of fixed lengths called capped collections (quantitative set. Capped collections is the only set that maintains the insertion sequence. If the maximum capacity is reached, the first element is overwritten. That is to say, the capped collection behavior is similar to a circular queue. A special cursor type, called tailable cursor, can be used in capped collection. When the result is returned, this cursor will not be closed, but will continue to wait for more results to return. That is to say, if a new record is inserted into the capped collection, the cursor will return automatically.
  14. Drivers in multiple languages are currently provided.
  15. Deployment: MongoDB uses memory-mapped files (memory ing files). Therefore, the maximum data size on 32-bit machines is 2 GB, at the same time, the MongoDB server can only run on the small-end system.
  16. Replication: MongoDB should not be deployed on fewer than two servers, that is, at least one server serves as the master and the other server as the slave. The Master can be used for reading and writing, while the slave can copy data from the master, but it can only perform read or backup operations. Developers can enable one operation to be replicated to multiple servers as needed.

The following code starts a master server and the corresponding slave server:

$ mkdir –p ~/dbs/master ~/dbs/slave$ ./mongod –master –port 10000 –dbpath ~/dbs/master$ ./mongod –slave  --port10001 –dbpath ~/dbs/slave  -- source localhost:10000
Additional knowledge

The so-called "Collenction-Orented" means that data is stored in a data set by groups and is called a collection ). Each set has a unique identification name in the database and can contain an infinite number of documents. The concept of a set is similar to that of a table in a relational database service (RDBMS). The difference is that it does not need to define any schema ).

Schema-free means that we do not need to know any schema definitions for the files stored in the mongodb database. If necessary, you can store files of different structures in the same database.

The document stored in the set is saved as a key-value pair. The key uniquely identifies a document, which is a string type, and the value can be a complex file type. We call this storage form BSON (Binary Serialized dOcument Format ).

MongoDB stores data in files (the default path is/data/db) and uses memory ing files for management to improve efficiency. MongoDB's main goal is to build a bridge between key/value storage (providing high performance and high scalability) and traditional RDBMS systems (rich functions, combines the advantages of both.

Mongo is applicable to the following scenarios:

  • Website data: Mongo is ideal for real-time insertion, update, and query, as well as the replication and high scalability required for real-time website data storage.
  • Cache: because of its high performance, Mongo is also suitable for serving as a cache layer for information infrastructure. After the system is restarted, the persistent cache layer established by Mongo can avoid data source overload at the lower layer.
  • Large-sized and low-value data: traditional relational databases may be expensive to store some data. Previously, programmers often choose traditional files for storage.
  • High scalability: Mongo is ideal for databases consisting of dozens or hundreds of servers. The Mongo roadmap contains built-in support for the MapReduce engine.
  • For object and JSON Data Storage: Mongo's BSON data format is very suitable for storing and querying document-based data.

Naturally, there are some restrictions on the use of MongoDB, for example, it is not suitable:

  • A highly transactional system, such as a banking or accounting system. Traditional relational databases are still more suitable for applications that require a large number of atomic complex transactions.
  • Traditional Business Intelligence applications: BI databases for specific problems will produce highly optimized query methods. For such applications, data warehouse may be a more appropriate choice.
  • SQL Problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.