MongoDB Combat (2) tool Set and special magic method

Source: Internet
Author: User
Tags comments log mongodb

First, MongoDB start-up mode

MongoDB supports the configuration file startup in addition to supporting the command-line startup method to start the database by reading the startup configuration file, for example, the following configuration file

You can use the following command./mongod-f/etc/mongodb.conf

MongoDB parameter Description

DBPath: Data file storage path each database creates a subdirectory in it to prevent the same instance from running multiple times Mongod.lock also saved in this directory. LogPath error log file logappend error log in Append mode default is overwrite mode BIND_IP external service binding IP is generally set to null and binding on all available IP on this machine, if necessary, can specify port external service ports separately. Web management port on the basis of this port +1000 fork after the Daemon Form run service Journal open log function to reduce the recovery time of single machine failure by saving the operation log to replace the Dur parameters in the 1.7.5 version after the 1.8 version. The time unit for the Syncdelay system to refresh the disk in seconds is 60 seconds by default. Directoryperdb Each db is stored in a separate directory. It is recommended that you set this parameter. A separate tablespace with MySQL resembles the Maxconns maximum number of connections Repairpath the temporary directory when the repair is executed. The repair operation must be performed after the reboot if the journal exception down machine is not turned on.

Stopping a database Here's one thing to be aware of.

Use Kill-2 or pkill, but do not use kill-9 to kill mongodb processes that can cause MONGODB data corruption.

Second, the common tool set

MongoDB provides a series of useful tools in the bin directory that provide the convenience of MongoDB in operation and maintenance management. Bsondump: Dump files in Bson format to JSON-formatted data MONGO: The client command-line tool is actually a JS interpreter that supports JS syntax Mongod: each instance of the database server starts a process that can be fork to run in the background mongodump/ Mongorestore: Database backup and Recovery tools mongoexport/mongoimport: Data export and import tools Mongofiles:gridfs management tools enable access to two files MONGOs: Fragmented routing If the sharding feature is used, then the application connects to the MONGOs instead of the Mongod Mongosniff: The tool works like the tcpdump, except that he only monitors MONGODB-related packet requests and outputs them in the specified readability form Mongostat: Real-time performance monitoring tools

Three, some very important magic methods

1, $all match all of this operator with SQL syntax in the same but different is, in just meet () a value within, and $all must meet all the values within [] such as: Db.users.find ({age:{$all: [6,8]}); Can query out {name: ' David ', age:26,age:[6,8,9]} but query does not show {name: ' David ', age:26,age:[6,7,9]}

2, $mod modulo operation query age modulo 10 equals 0 data db.student.find ({age:{$mod: [10,1]}}) For example: The C1 table data is as follows: > Db.c1.find () {"_id": ObjectId ("" 4fb4af85afa87dc1bed94330 ")," age ": 7," length_1 ": {" _id ": ObjectId (" 4fb4af89afa87dc1bed94331 ")," age ": 8," lengt H_1 ": {_id": ObjectId ("4fb4af8cafa87dc1bed94332"), "age": 6, "length_1": 30}

Query age modulo 6 equals 1 data > Db.c1.find ({age: {$mod: [6, 1]}}) {"_id": ObjectId ("4fb4af85afa87dc1bed94330"), "age": 7, "le Ngth_1 ": 30}

You can see that only the data with age modulo 6 equals 1 is displayed. Other inconsistent data does not appear

3, the number of $size array elements for {name: ' David ', age:26,favorite_number:[6,7,9]} records match Db.users.find ({favorite_number:{$size: 3}}); Mismatched Db.users.find ({favorite_number:{$size: 2}});

4, $slice take the record of the specified segment in the array

Db.posts.find ({},{comments:{$slice: 5}})

Db.posts.find ({},{comments:{$slice: [20,10]}})

5, $ look at the example bar

{"_id": 1, "semester": 1, "grades": [70,87,90]}

{"_id": 2, "semester": 1, "grades": [90,88,92]}

{"_id": 3, "semester": 1, "grades": [85,100,90]}

{"_id": 4, "semester": 2, "grades": [79,85,80]}

{"_id": 5, "semester": 2, "grades": [88,88,92]}

{"_id": 6, "semester": 2, "grades": [95,90,96]}

Db.students.find ({semester:1,grades:{$gte: 85}},{"grades.$": 1})

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/extra/

This is the result.

{"_id": 1, "grades": [87]}

{"_id": 2, "grades": [90]}

{"_id": 3, "grades": [85]}

Four, stored procedures

MongoDB stored procedures are stored in the Db.system.js table, we imagine a simple SQL custom function as follows

Definition of stored procedures view and execute

This article comes from "phper-every day a little ~" blog, please be sure to keep this source http://janephp.blog.51cto.com/4439680/1322792

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.