A MongoDB Introduction:
by querying some information on the Internet to introduce the advantages of MongoDB :MongoDB is a document-oriented database, currently developed and maintained by 10gen, it is rich in functionality, complete, can completely replace MySQL. In the process of using MongoDB to prototype a product, we summarize some of the highlights of Monogdb:
1 use JSON-style syntax, easy to grasp and understand: MongoDB uses the variant Bson JSON as the internal storage format and syntax. The JSON-style syntax is used for MONGODB operations, and the data submitted or received by the client is presented in JSON form. Compared to SQL, it is more intuitive, easy to understand and master.
2 schema-less, supporting embedding of sub-documents: MongoDB is a schema-free document database. A database can have multiple collection, and each collection is a collection of documents. Table and row for collection and document and traditional databases are not equivalent. No need to define collection in advance, can be created at any time. Collection can contain document records with different schemas. This means that the document in your previous record has 3 properties, and the next document can have 10 properties, the type of the property can be either a basic data type (such as a number, a string, a date, and so on), an array or hash, or even a subdocument (embed document). In this way, the inverse normalization (denormalizing) data model can be implemented to improve the speed of the query. Figure 1 MongoDB is a schema-free document database Figure 2 is an example where works and comments can be designed as a collection, comments as sub-documents embedded in the comments attribute of art, The reply to the comment is embedded in the replies property as a subdocument of the comment sub-document. In this design mode, all relevant information can be obtained by retrieving the work ID once.
3 in MongoDB, do not emphasize the data must be normalize, many occasions are recommended de-normalize, developers can throw away the traditional relational database of the various paradigms of limitations, do not need to map all the entities into a collection, Just define the top-level class. MongoDB's document model makes it easy for us to map our own object to the collection for storage. Figure 2 MongoDB Support embedded sub-document easy-to-use Query method: MongoDB in the query is very comfortable, no SQL difficult to remember the syntax, directly using JSON, quite intuitive. For different development languages, you can query using its most basic array or hash column. With additional OPERATOR,MONGODB support range queries, regular expression queries, queries for properties within a subdocument, you can replace SQL queries for most of the original tasks. CRUD is simpler and supports In-place update: As long as an array is defined, then the Insert/update method passed to MongoDB is automatically inserted or updated; For update mode, MONGODB supports a upsert option, namely: " Insert "If the record exists so updated. MongoDB's Update method also supports modifier, which enables immediate updates on the server through modifier, eliminating the communication between the client and the service side. These modifer allow MongoDB to have similar functions as Redis, memcached, and so on: simpler and faster than MYSQL,MONODB.
Two installation MongoDB
Before you install MongoDB, first download MongoDB before installing
2.1 Downloading source files
MongoDB's official website is: http://www.mongodb.org/
The latest version of MongoDB is downloaded under the Download menu on the official website: http://www.mongodb.org/downloads
I chose Windows 32-bit 2.6.6 version
MongoDB for. NET Driver Development Kit is located on the official website of the driver menu (including other language development links): Https://github.com/mongodb/mongo-csharp-driver/downloads
My operating system for WINDOWS7 Professional Edition, choose MongoDB version for Windows 32-bit 1.8.1, development package for VS2012 version, after downloading the source file is: Mongodb-win32-i386-2.6.6.zip
We can also look at what's underneath the bin directory after unpacking:
2.2 Installing the database
Here we install the database into the machine's F-drive, of course, we can also be installed in any one of the disks as needed. Here we need to create a folder:
F:\MONGODB\DATA\DB Create the Data folder below the MongoDB folder and create the DB folder under Data, which is important to store database data files.
F:\mongodb\logs\mongodb.log Create the Logs folder under the MongoDB folder and create the Mongodb.log file under the folder, which is mainly for the system log files, these folders must be created manually.
2.3 Start MongoDB
Enter the DOS environment, enter the F:\mongodb\data\db folder, use the Mongod.exe tool to start MongoDB, start the command is: MongoDB--dbpath F:\mongodb\data\bin, this directory is we just created Built directory, so that we can start MongoDB, and start monitoring, we can also test whether the database is started, in the browser input: http://localhost:27017/, you can see the following prompt:
You is trying to access MongoDB on the native driver port. For HTTP diagnostic access, add the port number see this prompt for our database to be able to listen successfully.
2.4 Installing as a Windows service
It would be cumbersome to use this approach every time the database is started, so we consider installing it as a Windows service.
Run Cmd.exe
> CD F:
> CD F:\mongodb\bin
> F:\mongodb\bin>mongod--dbpath F:\mongodb\data\db--logpath F:\mongodb\logs\mongodb.log--install-- ServiceName "MongoDB"
Here Mongodb.log is the log file that was started,--servicename the "MongoDB" service named MongoDB
Start the MongoDB service you created
net start MongoDB (start MongoDB service) net stop MongoDB (stop MongoDB Service) and then check in the service to see if the service is started, so that after each power-on, the service will be started to run the service without Must start the service every time.
It is important to note that when you open cmd on my computer, you must open it with administrator privileges, and then execute the relevant code to properly create the Windows service, which is especially important to note that the permissions that may be granted vary from one Windows operating system to another. If you do not open cmd with administrator privileges and then run these programs, the "Access Denied" prompt will appear in Logs\mongodb.log, which requires attention.
Install MongoDB (made into a Windows service) and load the C # driver