Demand:A colleague from the off-duty operation sent a requirement to count the number of occurrences of a field (_ID) in all document in a collection in the database. The range of the _id field is 0-4000.Suppose collection is like this:{ 123},{
MongoDB Basic Command
>show DBS//Display a list of current data
>DB//Display the current database object or collection
>use ' DB name '//connect to a specified database
Keep the database name:
Admin:
Common directives1. Go to the heavyDb.runcommand ({distinct: ' person ', key: ' Home '}); 2. GroupingDb.runcommand ({group:{ns: Collection name, key: Grouped key, initial: initialization, $reduce: decomposition, Condition: condition, Finalize:
1. How to read data from a backup nodeDefault is not allowed, the following error will be reported:Testreplset:secondary> Show dbs- -19t10:03.196+0800 E QUERY "OK"0"errmsg" " Not master and Slaveok=false""code"13435If you want to allow the backup
1. Documentation{"Greeting": "Hello,world", "foo": 3} The key/value pairs in the document are ordered, and the following document is a completely different two document from the document above. {"Foo": 3, "greeting": "Hello,world"}2. Usage
MongoDB comes with a JavaScript Shell, so it is possible to use the JS syntax in it.Insert operation:Single Insertvar single={"name":"mei"," Age ":}db.user.insert (single);Loop insertvar single={"name":"tinyphp","num ":",} for(var i=0;i5; i++) {
1>, synchronization: Replication is used to back up data between multiple servers.The replication functionality of MongoDB is implemented using the log Oplog, the operations log contains each write operation of the master node.Oplog is a fixed
MONGO additions and deletions to searchShow DBS shows all DBTo which db the use Fengdb is converted, without which a new db is created automaticallyDB Displays the current operation's DBDb.fengDb.insert ({"Name": "Fengnovo"}) adds a record to the
1. ConceptSharding (sharding) refers to the process of splitting data and dispersing it across different machines. This concept is sometimes represented by partitioning (partitioning). Spread the data across different machines without the need for
1. Create a CollectionThere are two ways to display create and implicitly createDisplay creation can use command Db.createcollection ("collection name")Implicit creation can use the command DB. Collection name. Insert ({}), which refers to creating
Next, I will talk about the group function of mongodb, which is quite powerful. It is quite complicated to use, such as find (), skip (), and distinct.Test data The code is as follows:Copy code > Db. fruit. find ();{"_ Id": 1, "category": "fruit"
Db. copyDatabase ("from", "to", "127.0.0.1: 16161 ");Replace the from library on 127.0.0.1. Copy to the to library.This has an additional benefit. That is, the from database may have deleted the data. We know that the disk space will not be released
By default, a _ id field is used as the autoincrement auto-increment implementation. The _ id field type is objectid (objectid is a 12-byte BSON type ). ObjectId.Now, due to database migration, some of the central mysql locations tables in the
$ Push: add an element to the document array. If this array is not available, the array is automatically added. The code is as follows:Copy code Db. users. insert ({"name": "zhang "})Db. users. update ({"name": "zhang" },{ "$ push": {"emails":
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