MongoDB Learning--Continuous update

Source: Internet
Author: User
Tags findone mongodb download mongo shell

Refer to MongoDB's authoritative guide, the learning phase. We have a lot of communication. Continue to update this article

MongoDB's Strengths
MongoDB has a rich data model and is a document-oriented database.

Easy extension. Ability to cut data between multiple servers.

Developers just need to focus on writing apps. Assume that more data is needed. Simply add a new machine to the cluster and let the database handle the rest of it.

Rich functionality, such as indexing, storing JavaScript, aggregation, fixed collections. File storage.

Join (join) and complex multiline things are not supported.

Superior performance is the primary goal of MongoDB, and the default storage engine uses a memory-mapped file. Hand over the memory management work to the operating system.

Easy to manage, MongoDB tries to get the server to manage the database itself. In addition to starting database server. Almost no administrative action is necessary.

Assuming that the primary server is hung up, it will proactively switch to the standby server.

MongoDB Download and Installation
first go to MongoDB official website, according to the system model select the version number to download. Here is an example of the CENTOS64 bit
    #下载> wgetHTTPS://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0. 4. tgz > TAR-ZXVF mongodb-linux-x86_64-3.0. 4. tgz > MV mongodb-linux-x86_64-3.0. 4/usr/Local/mongodb > cd/usr/Local/mongodb > MkDir db > MkDir logs > Vim bin/mongodb.conf#加入下面内容dbpath=/usr/Local/mongodb/db logpath=/usr/Local/mongodb/logs/mongodb.Logport=27017fork=true    #又一次绑定mongodb的配置文件地址和訪问IP>/usr/Local/mongodb/bin/mongod--bind_ip localhost-f/usr/local/mongodb/bin/mongodb.conf    #启动MongoDB>/usr/Local/mongodb/bin/mongod--config/usr/local/mongodb/bin/mongodb.conf    #測试是否开启成功进入mongodb的shell模式>/usr/Local/mongodb/bin/mongo > Show DBS#没有异常的话安装启动成功了. 
The basic concept of MongoDB

A document is a basic unit of data in MongoDB, similar to a row in a relational database.

In a similar way. A collection can be seen as a table without schemas.

A single instance of MongoDB can accommodate multiple independent databases. Each has its own collection and permissions.

MongoDB comes with a powerful JavaScript shell, a tool that works great for managing MongoDB instances and manipulating data.

Each document has a special key "_id", which is unique within the collection where the document is located.

MongoDB Shell operation
Execute Shell
    #进入shell模式>/usr/local/mongodb/bin/mongo#执行简单的计算> x= $     $> x/5     +    #还可充分利用JavaScript的标准库> Math.sin (Math.PI/2)1>"Hello world!". replace ("World","MongoDB") Hello mongodb!#shell (CRUD)    #创建tets数据库> Use test; > DB Test#创建一个用户> user={"Name":"Zhangsan","Age": -}; {"Name":"Zhangsan","Age": -} > Db.users.insert (user); Writeresult ({"ninserted":1})#查询    #find会返回集合里的全部记录, a maximum of 20 data is displayed in the shell, and FindOne displays a single piece of data> Db.users.findOne (); {"_id": ObjectId ("55b59ee00882afbc7416fed4"),"Name":"Zhangsan","Age": -}#更新    #改动name =zhangsan User's age is 20, add personality sex=1> user.sex=1    1> user.age= -     -> Db.users.update ({"Name":"Zhangsan"},user); Writeresult ({"Nmatched":1,"nupserted":0,"Nmodified":1}) > Db.users.findOne (); {"_id": ObjectId ("55b59ee00882afbc7416fed4"),"Name":"Zhangsan","Age": -,"Sex":1}#删除> Db.users.remove ({"Name":"Zhangsan"}); Writeresult ({"Nremoved":1})#shell帮助文档> Help Db.help ()-On DB Methods Db.mycoll.help () Help on collection methods                   Sh.help () sharding helpers rs.help () replica set helpers help admin Administrative help and connect connecting to a DB Help keys key s                     Hortcuts Help Misc Misc Things to know help Mr MapReduce show DBS Show database names show collections show collectionsinchCurrent database show users show UsersinchCurrent database show Profiles show most recent system.profile entries withTime >=1Ms Show logs show the accessible logger names show log [name] prints out the last SE Gment of LoginchMemory' Global '  isDefault use <db_name> Set current database Db.foo.find () List objectsinchCollection Foo Db.foo.find ({a:1}) List objectsinchFoo where a = =1It result of the last line evaluated;                         Use to further iterate dbquery.shellbatchsize = X Set default number of items to display on shell exit Quit the MONGO shell#了解函数源码. For example, the Update method. Input without parentheses> Db.foo.update

MongoDB Learning--Continuous update

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.