NoSQL mongodb--Database Configuration and preliminary use

Source: Internet
Author: User
Tags findone unique id





1.NOSQL Introduction


NOSQL (not only Sql) refers to a non-relational database. The next generation of databases mainly solves several key points: non-relational, distributed, open-source, horizontally extensible. The original goal was for large-scale Web applications, which began in the early 2009 with features such as freedom of mode, support for simple replication, simple APIs, eventual consistency (non-acid), high-capacity data, and so on. NoSQL is the most used when the number of key-value storage, of course, there are other document-type, column storage, graph database, XML database and so on.



A common NoSQL database:


 
CouchDB
Redis
MongoDB
Neo4j
HBase
BigTable


NoSQL Database Pros and Cons:


    • Advantages: Simple expansion, fast reading and writing, low cost, flexible data model
    • Disadvantage: does not provide support for SQL, not rich in support features, the existing product department is mature enough
2.MongoDB Introduction


MongoDB is a high-performance, open-source, modeless document-based database that is a popular one in the current NoSQL database. It can be used in many scenarios to replace the traditional relational database or key/value storage methods. MONGO is developed using C + +. MONGO's official website address is: http://www.mongodb.org/.



MongoDB Main Features:


    • Collection-oriented storage for easy storage of object-type data
    • Mode freedom
    • Support Dynamic Query
    • Full index support, including internal objects
    • Support for replication and failure recovery
    • Use efficient binary data storage, including large objects
    • File storage format is Bson (an extension of JSON)


The basic concepts in MongoDB:


    • Document is the basic unit of data in MongoDB, very similar to a row in a relational database system (but more complex than a row)
    • A collection (collection) is a set of documents that, if a document in MongoDB is similar to a row in a relational database, the collection is like a table
    • A single instance of MongoDB can hold multiple independent databases, each with its own collection and permissions
    • MongoDB comes with a simple but powerful JavaScript shell, a tool that is very useful for managing MongoDB instances and manipulating data
    • Each document has a special key "_id", which is unique in the collection where the document is located, equivalent to the primary key of the table in the relational database


MongoDB Data type:


Data type Description Example
null means null or undefined object {"x": null}
Boolean true or false: true or false {"x": true}
32-bit integer 32-bit integer. The shell does not support this type, the shell will be converted to 64-bit floating point by default
64-bit integer 64-bit integer. The shell does not support this type, the shell will be converted to 64-bit floating point by default
64-bit floating point number 64-bit floating point number. The number in the shell is this type {"x": 3.14, "y": 3}
String UTF-8 string {"foo": "bar"}
Symbol shell does not support, the shell will automatically convert the data of the symbol type in the database into a string
Object id The 12-byte unique id of the document {"id": ObjectId ()}
Date The number of milliseconds since the standard era {"date": new Date ()}
Regular expressions Documents can contain regular expressions, following the syntax of JavaScript {"foo": / foobar / i}
Code Documents can contain JavaScript code {"x": function () {}}
Undefined {"x": undefined}
Array A collection or list of values {"arr": ["a", "b"]}
Embedded document Document can be used as the value of a key in the document {"x": {"foo": "bar"}} 
3.MongoDB 3.2.9 Installation


Download URL: Https://www.mongodb.com/download-center?jmp=nav



Installation












Directory structure






Bin file:



The file folder is executable files, configuration files, dynamic link library, etc., bin is binary abbreviation, which means binary. Because exe,dll,ocx these executables are binary, the folder name uses "Bin", which is the result of previous habits.






License-gnu-agpl-3.0.txt-a lightweight social customer management system



A more detailed document is presented: http://blog.csdn.net/kk185800961/article/details/45001219


4.MongoDB Configuration 4.1 Set up working directory


(1) Set up the data storage directory D:\ImprtantSoft\MongoDB\MongoDBDATA\data



(2) Create a log file D:\ImprtantSoft\MongoDB\MongoDBDATA\logs



(3) Setting System variables









To facilitate the management of MONGODB from the console, you do not have to go into the d:mongodb every time. My Computer--attribute--advanced--environment variable--path:d:\imprtantsoft\mongodb\server\3.2\bin in the system variable;





4.2 Starting the Mongdb service


Go to the console and enter Mongod--dbpath D:\ImprtantSoft\MongoDB\MongoDBDATA\data






A series of files are generated under the data empty file created after running:






Or create a bat file, the bat file is a DOS batch file. A batch file is a unformatted text file that contains one or more commands. It has a. bat or. cmd file name extension. At the command prompt, type the name of the batch file, or double-click the batch file, and the system calls Cmd.exe to run them one by one in the order in which the commands appear in the file. Use a batch file (also known as a batch program or script) to simplify routine or repetitive tasks.









Double-click Mongodb.bat such as: So the service is started (previous version)






It will normally appear as follows:



Enter http://localhost:27017/in the browser



There will be an IT looks like you is trying to access MongoDB over HTTP on the native driver port. Indicates that the service has been started:






Do not close the current console window, and another console, enter MONGO such as: indicates that the connection to Mongdb was successful.






Or create a bat file






Write MONGO 127.0.0.1:27017/admin in Mongodb27017admin.bat file






Direct use of Administrator level, high level of operation



Run as follows:






Write MONGO 127.0.0.1:27017 in Mongodb27017test.bat file






Run as follows:






At this point, the test user is entered.


5.MongoDB Basic Operation




use foobar
show dbs
db.persons.insert({name:”wangchao”})
show collections
db.persons.find()
db.persons.findOne() var p=db.persons.findOne()
db.persons.update(p,{name:”uspcat”})
db.persons.remove({name:”uspcat”})


Run results


>mongo 127.0.0.1:27017 MongoDB shell version: 3.2.9 connecting to: 127.0.0.1:27017/test > show dbs
local 0.000GB > use foobar
switched to db foobar > show dbs
local 0.000GB > db.persons.insert({name:"Raining_wcc"})
WriteResult({ "nInserted" : 1 }) > show collections
persons > db.persons.find()
{ "_id" : ObjectId("57b4044e85a1a6b1162384a2"), "name" : "Raining_wcc" } > db.persons.insert({parterner:"superman"})
WriteResult({ "nInserted" : 1 }) > db.persons.find()
{ "_id" : ObjectId("57b4044e85a1a6b1162384a2"), "name" : "Raining_wcc" }
{ "_id" : ObjectId("57b404d285a1a6b1162384a3"), "parterner" : "superman" } > db.persons.findOne()
{ "_id" : ObjectId("57b4044e85a1a6b1162384a2"), "name" : "Raining_wcc" } > var p = db.persons.findOne() > p
{ "_id" : ObjectId("57b4044e85a1a6b1162384a2"), "name" : "Raining_wcc" } > db.persons.update(p,{name:"wcc"})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.persons.find()
{ "_id" : ObjectId("57b4044e85a1a6b1162384a2"), "name" : "wcc" }
{ "_id" : ObjectId("57b404d285a1a6b1162384a3"), "parterner" : "superman" } > db.persons.insert({name:"supergirl"})
WriteResult({ "nInserted" : 1 }) > db.persons.find()
{ "_id" : ObjectId("57b4044e85a1a6b1162384a2"), "name" : "wcc" }
{ "_id" : ObjectId("57b404d285a1a6b1162384a3"), "parterner" : "superman" }
{ "_id" : ObjectId("57b4057185a1a6b1162384a4"), "name" : "supergirl" } > db.persons.remove({name:"wcc"})
WriteResult({ "nRemoved" : 1 }) > db.persons.find()
{ "_id" : ObjectId("57b404d285a1a6b1162384a3"), "parterner" : "superman" }
{ "_id" : ObjectId("57b4057185a1a6b1162384a4"), "name" : "supergirl" } >





This article link: http://www.cnblogs.com/homewch/p/5779192.html



NoSQL mongodb--Database Configuration and preliminary use


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.