Mongodb startup and basic commands, mongodb startup commands

Source: Internet
Author: User

Mongodb startup and basic commands, mongodb startup commands

1. Start mongodb with Parameters

./Mongod -- dbpath =/usr/local/mongo/mongodb/data -- fork -- logpath =/usr/local/mongo/mongodb/logs -- nohttpinterface

2../mongo connect to mongodb

3. Use ruby to connect to the MongoDB Database

Install ruby and rubygems

Configure the connect. rb File

Run ruby connect. rb to run the connection.

4. Commands

Mongo added

Db. users. insert ({name: "Jony "})

Modify common mongo

Db. users. update ({name: "Jony"}, {$ set: {country: "Fujian "}})

If there is no conutry field in the users set, it is equivalent to adding the country field. If so, modify

Db. users. update ({name: "Jony"}, {country: "Fujian "})

If no $ set exists, the name field is directly deleted and replaced with the country field.

Common mongo Lookup

Db. users. find () or db. users. find ({name: "Jony" },{ country: "Fujian "})

It command

Display the next group of information

Create a large collection

For (I = 0; I <20000; I ++ ){

Db. numbers. save ({num: I });

}

Create an index

Db. numbers. createIndex ({num: 1 })

View Indexes

Db. numbers. getIndexes ()

Display database information

Show dbs

Show all set information

Show collections

View Collection status

Db. stats () or db. numbers. stats ()

Ruby connection Mongo command

Query a set

$ Users. find (). each do | user | put user end

The preceding statement indicates that

Iterate the data in the users set into the user and output the data.

Modify

$ Users. find ({"name" => "Jony"}). update_one ({"$ set" =>{ "city" => "Fuzhou "}})

Delete

$ Users. find ({"name" => "Jony"}). delete_one deletes the first matched

$ Users. find ({"name" => "Jony"}). delete_many delete all matched

Users. drop Delete All sets

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.