MongoDB in my this C # eye-01 First Knowledge

Source: Internet
Author: User

Although not a technical Daniel, but the team leader recommended to look at, and we are doing the project, similar to the resource center, involving a variety of weird data types of different sub-libraries, so so far has been used this way:
①maindata all values in the table, the most varied library data is stored in JSON
②json all fields correspond to an index table for indexing
③ A metadata table stores all possible JSON fields
④ If the field is a value of the selection type, it is stored by a new table

From this framework, it is good, but the problem is that JSON and other tables, such as inserting, modifying, updating, will be more crazy ...

Since the human identifiable deserialization of the data is two kinds, XML and JSON, and MongoDB is similar to this, we can start with the database.

The first mention of its Windows version and installation related, since the reference to the database, we have to mention MONGO version of the multi-platform, really and Microsoft is sung, but the attendant problem comes, that is, Microsoft only focus on their platform, so they do things must be very useful. What is the MONGO interface? It is a pity that the official shell only has a command line and has not yet formally launched a very useful UI, so we can only rely on third parties.

Download mongo:http://mongodb.org/from the official website first
The version I'm using now is 3.0. Find a place to install, this process is very fast, of course, the database is recommended 64-bit system, may need to update a patch under Win7, late version may be changed.
After that you will find that there are many more command-line tools installed in the home directory, which is the favorite of the Code writers ... Although I have no confidence in my typing

The most important is the Mongod.exe service and Mongo.exe operation side, of course, other such as monitoring tool import and export tool is also necessary for the database manager, so the contents of this directory to use good, you have to learn some command-line knowledge, such as CMD, such as the system environment variables, let you start them faster.

So, how do you start it? The main way to start MongoDB is by reading the config configuration file, start a server with the Mongod host, the specific config configuration can go to the manual view, very detailed, but also very complex, below I issued a relatively simple configuration, which is a YAML configuration, is the second and new way of MONGO support:

systemlog:destination:file## #日志存储位置 Path:c:\data\mongodb_simple\log/mongod.log logappend:truestorage:## Journal Configuration Journal:  enabled:true# #数据文件存储位置 dbpath:c:\data\mongodb_simple\data# #是否一个库一个文件夹 directoryperdb:true# #数据引擎 engine:wiredtiger# #WT引擎配置 wiredtiger:  engineconfig:# #WT最大使用cache (adjusted according to the actual   server)4# # Whether the index is also stored separately by database name   directoryforindexes:true# #表压缩配置  collectionconfig:   blockcompressor:zlib# #索引配置  Indexconfig:   27017

Next is the start, here I use the absolute path, it seems more intuitive, is to give the program a parameter-F:

"C:\Program Files\mongodb\server\3.0\bin\mongod.exe"-F "C:\data\mongodb_simple\conf\simple1.conf"

OK, if the database fails to start, you can start cmd, execute it once at the command line, and see what the hint is, which is the simplest and most intuitive way. Let's try to manipulate the database with a simple shell provider. Simply start the Mongo.exe and connect to the database:

C:\users\zhouzhi> "C:\Program files\mongodb\server\3.0\bin\mongo.exe" 2015-09-30t14:23:39.621+0800 I CONTROL  filesshell version:3.0.1connecting To:test>

Here I directly executed the mongo.exe, without attaching any parameters, directly connected to the default location of localhost:27017, see it after the successful connection also automatically jump to the test library, then we look at this database there are several libraries:

> show dbslocal  0. 000GBtest   0. 000GB>

Mongo.exe is often called the shell, it is based on JavaScript, additional customization supplemented by a set of command scripts, show DBS this built-in command, it shows the library contains, of course, if you have never manipulated the library will not exist.
Next I go into a library and insert a record:

connecting To:test> show dbslocal  0. 000GBtest   0. 000GB> Use textswitched to db text> db. Maindata.insert ({name: ' 3tai ', Age:25,url: ' http://www.cnblogs.com/3Tai/', Time:new"ninserted": 1 })>

When we insert, we use the basic JavaScript writing, here to pay attention to the string, number, time, there are several different types, after execution prompted a change, below we look at the document just inserted, here to use the simplest and most direct search:

> db. Maindata.find (). Pretty () {        "_id": ObjectId ("560b83be22f39ad2d6004365"),        "name": "3tai",         "Age": +,        "url": "http://www.cnblogs.com/3Tai/",        "Time": Isodate (" 2015-09-30t06:39:58.788z ")}>

Using the Find function, you can get the result, the following pretty function, you can format the result, is to optimize the output effect.
At this point, we have successfully run MongoDB, next time we are in line with C #

MongoDB in my this C # eye-01 First Knowledge

Related Article

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.