Today, the basic operation of MongoDB is recorded, this is only the most basic, so it should be mastered.
Database
A database is a collection of physical containers. Each database has its own set of files on the file system. A single MongoDB server typically has multiple databases.
Collection
A collection is a set of MongoDB documents. It is equivalent to an RDBMS table. The collection exists in a single database. The collection does not execute the pattern. The documents within the collection can have different areas. Typically, all files in a collection are of the same or related purpose.
Document
A document is a set of key-value pairs. File dynamic mode. Dynamic mode refers to documents in the same collection that do not require a collection of common fields that have the same field or structure group, and can accommodate different types of data.
A comparison between relational database and MongoDB
See this watch I think you must have your own understanding of MongoDB.
MongoDB supports a list of many data types as given below:
String: This is the most commonly used data type to store data. The string in MongoDB must be a valid UTF-8.
Integer: This type is used to store a numeric value. The integer can be either 32-bit or 64-bit, depending on your server.
Boolean: This type is used to store a Boolean value (True/false).
Double: This type is used to store floating-point values.
Min/max keys: This type is used to compare the lowest and highest values of the Bson element.
Arrays: Use this type of array or list or multiple values to store to a key.
Timestamp: Timestamp. This makes it easy to record when the file has been modified or added.
Object: This data type is used for embedded files.
Null: This type is used to store a null value.
Symbol: This data type is used for the same string, but it is usually reserved for languages of a particular symbol type.
Date: This data type is used to store the UNIX time format for the current date or time. You can specify your own date and time, date and year, month, day to create an object.
Object ID: This data type is used to store the document ID.
Binary data: This data type is used to store binaries.
Code: This data type is used to store JavaScript code in the document.
Regular expression: This data type is used to store regular expressions
Below to start the real operation MongoDB
Show DBS: View the list of databases
Use command: The command creates a new database and returns an existing database if it does not exist.
Use Mymongo (the database created in the Mymongo list does not exist.) To display the database, you need to insert it into at least one file, such as: Db.test.insert ({name: "Zhang San", Age: "18"})
Dropdatabase () Method: the Db.dropdatabase () command is used to delete an existing database. It will delete the selected database. If you have not selected any databases, then it will delete the default ' test ' database
createcollection () method:The db.createcollection (name, options) is used to create the collection. Name is the names of the collections. Options is a file that specifies a collection of configurations
Show Collections : You can view the list of created collections
In MongoDB, you do not need to create a collection. When inserting some files MongoDB automatically creates the collection.
Drop () method: Db.collection.drop () is used to delete a collection from the database.
The drop () method returns Trueif the selected successful collection is discarded, otherwise it will return false
Insert () method: To insert data into a MongoDB collection, you need to use the MongoDB Insert () or Save () method.
Here are two ways of querying, as described below. Here you can see me i inserted an array ["MongoDB", "Python", "Hadoop")
Here MyCollection1 is the name of the collection. If the collection does not exist in the database, MongoDB creates the collection and then inserts it into the document. We can also insert an array, the truth is the same, you can try it yourself.
Insert the document, if we do not specify the _id parameter, then mongodb this document assigns a unique objectid. _ID is a 12-byte hexadecimal number that is unique to each document in a collection.
Find () Method: Query collection data, the Find () method will display all files in an unstructured manner. The Pretty () method displays the data in a formatted fashion.
The above example has been shown. In addition to the find () method, there is a FindOne () method that returns a file.
Below is the conditional query:RDBMS WHERE clause and MongoDB equivalent statement
and usage
or usage
The limit () method and the skip () method are generally used as paging : To limit the records in MongoDB, you need to use the limit () method. The limit () method accepts a numeric parameter, which is the number of documents to display. The Skip () method also accepts numeric type parameters and uses the number of skipped documents
Remove () method: Used to remove a document from the collection. The Remove () method accepts two parameters. The first one is to delete the criteria, the second is the JUSTONE flag:
Deletion criteria: (optional) Delete the standard, depending on the file will be deleted.
Justone: (optional) If set to TRUE or 1, then delete only one file. If you have more than one record and you want to delete only the first record, set the Justone parameter in the Remove () method
- If you do not specify a delete condition, then MongoDB will delete the entire file from the collection
Update () method: Updates the document to update multiple needs to set the parameter ' multi ' to true
Sort () Method: Accepts a document that contains a list of fields together with their sort order. To specify sort order 1 and-1. 1 is used in ascending order, and-1 for descending order. Note that if sort precedence is not specified, then the sort () method displays the document in ascending order.
Just write it, get off work, have time to write some in-depth. I hope you will advise us.
30 minutes to let you know the basic MongoDB operation