MongoDB Basic Operations

Source: Internet
Author: User

MongoDB is written by the C + + language and is an open source database system based on distributed file storage.

In the case of high load, adding more nodes can guarantee the performance of the server.

MongoDB is designed to provide scalable, high-performance data storage solutions for Web applications.

MongoDB stores data as a document and data structures consist of key-value (key=>value) pairs. A MongoDB document is similar to a JSON object. Field values can contain other documents, arrays, and array of documents.

Basic operation:

Remote connection: mongo-u username-p password ip:port/dbname (library name)Show All libraries: Show DBSSelect a library: User dbCreate library: User NewdbnameDelete Library: db.dropdb ()View all collections: Show CollectionsAdd Collection: Db.collection.insert ({"Name", "Hello"}) if the collection does not exist, the collection is automatically created and the data is addedDb.collection.insertOne ({"Key", "value"})Db.collection.insertMany ([{"A", 1},{"B", 2},{"C", 3}])Delete collection: Db.collection.drop ()Empty Collection: Db.collection.remove ({})View collection: Db.collection.find ()Db.collection.find (). Pretty ()Update Collection: Db.collection.update ({"Key": "A"},{$set: {"A": "AAA"}},{multi:true}) is preceded by the Where condition of the update operation, followed by the data that needs to be updated. When there are multiple identical keys in the collection, MONGO only updates the first data, and with {multi:true} You can modify multiple documents of the same keysave ({...}) new features in version 3.2:Db.collection.updateOne ()Db.collection.updateMany () Multi not requiredWhere Condition: equals {key:value}less than {key:{$lt: value}}greater than {key:{$gt: value}}less than or equal to {key:{$lte: value}}greater than or equal to {key:{$gte: value}}not equal to {key:{$ne: value}}and {key1:value,key2:value2}OR {$or: [{key1:value1},{key2:value2}]}Fuzzy query: Db.collection.find ({key:/value/})contains query: Db.collection.find ({key:{$in: [Key,key2]}})does not include query: Db.collection.find ({key:{$nin: {key1,key2} }})de-weight: db.collection.distinct (value) Db.collection.find ({key:{$type: 2}) queries the key for a string type of data paging query Db.collection.find (). Limit (pagenumber). Skip (PageSize)Match data type $type

MongoDB Basic Operations

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.