MongoDB startup and underlying commands

Source: Internet
Author: User
Tags mongodb
1. Parameter Start MongoDB
./mongod--dbpath=/usr/local/mongo/mongodb/data--fork--logpath=/usr/local/mongo/mongodb/logs--nohttpinterface


2./mongo Connection MongoDB


3. Connect MongoDB database with Ruby


Installing Ruby and RubyGems


Configuring CONNECT.RB Files


Enter command: Ruby CONNECT.RB run Connection




4. Order
General MONGO New
Db.users.insert ({name: "Jony"})


General MONGO Modification
Db.users.update ({name: "Jony"},{$set: {country: "Fujian"}})
If there is no conutry field in the Users collection, it is equivalent to adding the Country field, if it exists, modify


Db.users.update ({name: "Jony"},{country: "Fujian"})
If there is no $set, the name field is deleted directly and replaced with the Country field


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


It command
Show next set 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 Index
Db.numbers.getIndexes ()




displaying database information
Show DBS


Show all collection Information
Show collections


View collection Status
Db.stats () or db.numbers.stats ()
















Ruby Connection MONGO Command


Query Collection
$users. Find (). |user| Put user end
The above statement means
Iterate the data in the Users collection into user output


Modify
$users. Find ({"name" => "Jony"}). Update_One ({"$set" =>{"City" => "Fuzhou"})


Delete


$users. Find ({"name" => "Jony"}). Delete_one deletes the first matching
$users. Find ({"name" => "Jony"}). Delete_many Delete all matching


Users.drop Delete all collections
















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.