MongoDB is an open source database project based on distributed file storage. Written in C ++. It is designed to provide a high-performance data storage solution that can be expanded for Web applications.
It features high performance, ease of deployment, and ease of use, making it easy to store data. Features:
- It is designed for centralized storage and is easy to store object-type data.
- Free mode.
- Supports dynamic query.
- Supports full indexing, including internal objects.
- Query is supported.
- Supports replication and fault recovery.
- Use efficient binary data storage, including large objects (such as videos ).
- Automatic fragment processing to support scalability at the cloud computing level
- Supports Ruby, Python, Java, C ++, PHP, and other languages.
- The file storage format is bson (a json extension)
- Accessible through the network
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 ).
The MongoDB server can run on Linux, windows, or OS X. It supports 32-bit and 64-bit applications. The default port is 27017. We recommend that you run on a 64-bit platform because MongoDB supports a maximum file size of 2 GB when running in 32-Bit mode.
MongoDB stores data in files (the default path is/data/DB) and uses memory ing files for management to improve efficiency.
Install it in Windows:
1. Download the 32-bit or 64-bit version file to the http://www.mongodb.org/display/DOCS/Downloads
2. decompress the file, for example, I decompress to E: \ workshop \ no SQL \ mongodb-win32-i386-1.4.2 \
3. Windows is stored in c: \ data \ dB. You can use the -- dbpath parameter to specify the storage directory and start it at startup. Create data directory e: \ workshop \ no SQL \ mongodb-win32-i386-1.4.2 \ bin \ data \ dB such as: e: \ workshop \ nosql \ mongodb-win32-i386-1.4.2 \ bin> "E: \ workshop \ no SQL \ mongodb-win32-i386-1.4.2 \ bin \ mongod.exe "-- dbpath. \ data \ DB
Start Database
Now we can use the built-in shell tool to operate the database (we can also use variousProgramming LanguageTo use MongoDB, the built-in shell tool can help us manage the database)
"Connecting to:" will display the name of the database you are using. If you want to change the database, you can: Use mydb
Using. Net to operate MongoDB is very simple. Download The .netdriver from github.com/samus/mongodb-csharpand use the driver in the project.ProgramSet.
To establish a MongoDB connection, you only need to specify the database to connect. This database may not exist. If it does not exist, MongoDB will first create this database for you. You can also specify the network address and port to connect to during connection.
String connstr = configurationmanager. receivettings ["simple"];
If (string. isnullorempty (connstr) throw new argumentnullexception ("connection string not found .");
Mongo = new Mongo (connstr );
Mongo. Connect ();
Configuration
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Deleetask>
<Add key = "simple" value = "Server = localhost: 27017"/>
</Appsettings>
</Configuration>
Each database has zero or multiple sets. You can obtain their list if needed:
Database simple = Mongo ["simple"];
List <string> collectionnames = simple. getcollectionnames ();
To obtain a specific set, you can specify the Set Name and use the getcollection () method or make the index:
Imongocollection categories = simple. getcollection ("categories ");
Imongocollection categories = simple ["categories"];
When you obtain this set object, you can perform operations such as adding, deleting, querying, and modifying data.
When you get a collection object, you can insert the document into this object.
VaR names = new string [] {"bluez", "Jazz", "classical", "rock", "oldies", "Heavy Metal "};
Foreach (string name in names)
{
Categories. insert (new document () {"name", name }});
}
To find the document we inserted in the previous step, you can use the findone () operation to obtain the first document in the set. This method returns a single document.
VaR Category = categories. findone (new document {"name", "bluez "}});
Console. writeline ("the ID findone" + category ["_ id"]);
For the convenience of normal use, register mongod as the system service "D: \ workshop \ Mongo \ mongodb-win32-x86_64-2.0.3 \ bin \ mongod" -- dbpath "D: \ workshop \ Mongo \ mongodb-win32-x86_64-2.0.3 \ data "-- logpath" D: \ workshop \ Mongo \ mongodb-win32-x86_64-2.0.3 \ log \ mongodblog. log "-- service -- servicename MongoDB
# Register as a system service and modify the service port D: \ MongoDB \ bin \ mongod -- dbpath "D: \ data" -- port 10001
Modify the registry and change-install to-service.
MongoDB: Windows Service
MongoDB Summary
Going nosql with MongoDB
Http://cookbook.mongodb.org/
Solution for MongoDB still reporting MMAP failed with out of memory error on 64-bit servers (with MySQL performance comparison test)
Using nosql through MongoDB
Http://msdn.microsoft.com/zh-cn/magazine/ee310029.aspx
Http://msdn.microsoft.com/zh-cn/magazine/ff714592.aspx
Http://msdn.microsoft.com/zh-cn/magazine/ff798277.aspx
http://www.ibm.com/developerworks/cn/opensource/os-mongodb4/index.html