MongoDB Basic concepts and common commands

Source: Internet
Author: User

MongoDB Basic concepts and common commandsMongo DB is currently in ITa non-relational database (NOSQL) that is popular in the industry, and its flexible data storage methods are favored by current it practitioners. Mongo DB is a good implementation of object-oriented thinking (Oo idea), in Mongo db each record is a document object. The biggest advantage of Mongo DB is that all data persistence requires no developers to write SQL statements manually, and it is easy to invoke methods to implement CRUD operations. compared with the traditional relational database, NoSQL database has the features of simple operation, free, open source, download at any time, and can be used for various commercial purposes. This makes NoSQL products widely used in a variety of large-scale portals and professional web sites, greatly reducing operating costs. In the 2010, with the rise of Internet Web2.0 Web sites, NoSQL has sparked a flurry of excitement in the country, including MongoDB. More and more industry companies have put MongoDB into the actual production environment, many start-up teams also use MongoDB as their preferred database, creating a very large number of mobile Internet applications. MongoDB's document model is free and flexible, allowing you to be more comfortable in the development process. MongoDB can handle Internet applications with large data volumes, high concurrency, and weak transactions. MongoDB's built-in horizontal scaling mechanism provides the ability to handle data volumes from millions to 1 billion levels, fully satisfying the data storage needs of Web2.0 and mobile Internet, and its out-of-the-box features greatly reduce the operational costs of small and medium-sized websites.As for the download and installation I will not explain here, I would like to talk about the Monbodb database common commands.
collection is equivalent to a data table. 1. Add :db.things.save ({"name":1)); Db.things.insert ({"Name": 1});
2.  query : query all db.things.find () that meet the criteria; The returned data only shows the name column db.things.find (null,{name:1}) Query for the first eligibleDb.things.findOne ();
condition query and loop output db.things.find ({x:4}). forEach (printjson);
Limit restriction: db.things.find (). limit (3);
3. Modification:Db.things.update ({name: "MONGO"},{$set: {name: "Mongo_new"}});
4. Delete: Db.things.remove ({name: "Mongo_new"});
5.Conditional operator
Db.collection.find ({"field": {$gt: Value}});
$GT Greater than
$it less than
$gte greater than or equal to
$ite less than or equal to
$all Match all Db.users.find ({age:{$all: [6,8]}});
$exists determine if a field has a record that queries all existing age fields: Db.users.find ({age:{$exists: true}});
$mod modulo operation Db.student.find ({age:{$mod: [10,1]}});
$ne Not equal to Db.things.find ({x:{$ne: 3}});
$in contains Db.things.find ({x:{$in: [2,4,6]}});
$nin does not contain
$size the number of array elements db.users.find ({favorite_number:{$size: 2}});
6.Regular TableThe name=b* match query does not match the record Db.users.find ({name:{$not:/^b.*/}});
7.Sort: db.users.find (). Sort ({age:1});//asc
Db.users.find (). Sort ({age:-1});//desc

MongoDB Basic concepts and common commands

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.