Description: mongodb[1] is a database based on distributed file storage. Written by the C + + language. Designed to provide scalable, high-performance data storage solutions for Web applications.
Mongodb
MONGODB[2] is a product between a relational database and a non-relational database, the most versatile of the non-relational databases, most like relational databases. The data structure he supports is very loose and is a JSON-like Bson format, so you can store more complex data types. MONGO's biggest feature is that the query language he supports is very powerful, and its syntax is a bit like an object-oriented query language that almost implements most of the functionality of a relational database single-table query, and also supports indexing of data.
Distributed File System (distributed) means that the physical storage resources managed by the file system are not necessarily directly connected to the local nodes, but are connected to the nodes through the computer network. The design of a distributed file system is based on client/server mode. A typical network might include multiple servers for multiple users to access. In addition, the peer-to feature allows some systems to play the dual role of the client and server.
HBase is a distributed, column-oriented, open-source database that comes from the Google paper "Bigtable: A distributed storage system of structured data" written by Fay Chang.
The Yonghong Data mart is a software that is based on proprietary technology developed for the storage and processing of information. Yonghong Data Mart's Distributed File Storage System (ZDFS) is a transformation and extension of Hadoop HDFs to manage and store files stored on all nodes in a server cluster.
The above is a brief introduction to MongoDB, by introducing the use of MongoDB in addition to understanding his basic data storage, but also to understand how distributed systems are deployed, and how to solve load balancing problems.
The following is a summary of my beginner's tutorial, which is familiar with basic commands, understanding MongoDB features, and so on.
A Basic use in command mode
- Database creation
Use database_name
- View Database
Show Dbsshow DBS
- Deleting a database
Db.dropdatabase ()
- Insert Document
Db.user.insert ({_id:1,name: ' Mybo '})
INSERT statement using JSON-like Bson
- Updating a document that already exists
Db.collection.update (
<query>,
<update>,
{
Upsert: <boolean>
Multi: <boolean>
Writeconcern: <document>
}
)
Parameter description:
- The query:update query condition, similar to that in SQL Update query, is behind.
- Update:update objects and some updated operators (such as $, $inc ... ) can also be understood as the SQL update query within the set after the
- Upsert: Optional, this parameter means that if there is no record of update, insert objnew,true as INSERT, default is False, do not insert.
- Multi: Optional, mongodb default is False, only update the first record found, if this parameter is true, will be found on the condition of a number of records update all.
- Writeconcern: Optional, throws an exception level.
Exmple:db.col.update ({' title ': ' MongoDB Tutorial '},{$set: {' title ': ' MongoDB '}},{multi:true})
- Replace document
Db.col.save ({
"_id": ObjectId ("56064f89ade2f21f36b03136"),
"title": "MongoDB",
"description": "MongoDB is a Nosql database",
"By": "Runoob",
"url": "Http://www.runoob.com",
"Tags": [
"MongoDB",
"NoSQL"
],
"Likes": 110
})
- Delete a document
Db.col.remove ({' title ': ' MongoDB Tutorial '})
Delete the first: db. Collection_name.remove (deletion_criteria,1)
- Delete all Documents
- Db.col.remove ({})
- Document Query
Db.col.find ()//query All
- Conditional query Examples
Db.col.find ({"likes": {$gt: $}, $or: [{"By": "Rookie Tutorial"},{"title": "MongoDB Tutorial"}]}). Pretty ()
- Conditional operator
- (>) Greater than-$GT
- (<) less than-$lt
- (>=) greater than or equal to-$gte
- (<=) less than or equal to-$lte
- Type operation
The $type operator is based on the Bson type to retrieve the matching data type in the collection and returns the result.
- Limit limits two data
Db.col.find ({},{"title": 1,_id:0}). Limit (2)
{"title": "PHP Tutorial"}
{"title": "Java Tutorial"}
- In addition to using the limit () method to read a specified amount of data, we can use the skip () method to skip a specified number of data, Skip The method also accepts a numeric parameter as the number of skipped record bars.
Db.col.find ({},{"title": 1,_id:0}). Limit (1). Skip (1)
{"title": "Java Tutorial"}
- Sort
Db. Collection_name.find (). Sort ({key:1})//1 Ascending 2 Descending
- Build an index
B.col.ensureindex ({"title": 1}).
18. Aggregation
MongoDB Aggregation (aggregate) is primarily used to process data (such as statistical averages, sums, etc.) and returns the computed data results. A bit like the count (*) in the SQL statement.
Db.mycol.aggregate ([{$group: {_id: "$by _user", num_tutorial: {$sum: 1}}])
{
"Result": [
{
"_id": "w3cschool.cc",
"Num_tutorial": 2
},
{
"_id": "Neo4j",
"Num_tutorial": 1
}
],
"OK": 1
}
- Regular expressions
Db.posts.find ({post_text:{$regex: "w3cschool.cc", $options: "$i"}})
The above is a command-line operation for MongoDB, but for programmers it is easy for us to use some simple commands, but for as a Java developer I want to be proficient in understanding how to call in Java.
MongoDB basic Commands