MongoDB in a Clustered collection (Collection/coll) equivalent to a table in MySQL
The document is equivalent to every row of data in MySQL
Common commands
1. Get Help commands
Db.help () db. Table name. Help () db. Table name. Find (). Help () Rs.help ()
2. Switch/CREATE Database
Use database name NOTE: MongoDB database can be used first, then created, when creating a collection (table), the current database will automatically create an example: There is a database for SUTDENTDB, to switch to this database is: use Studentdb
3. Querying all databases
Show DBS Example:> show Dbsadmin 0.078GBlocal 0.078GBstudentdb 0.078GBtest 0.078GB
4. Delete the currently used database
Db.dropdatabase () example:> use testswitched to DB test> db.dropdatabase () {"Dropped": "Test", "OK": 1}> show Dbsadm In 0.078GBlocal 0.078GBstudentdb 0.078GB
5. View the currently used database
Db.getname () example:> use studentdbswitched to DB studentdb> db.getname () studentdb
6. Display the current DB status
Db.stats ()
7. Current DB version
> db.version () 2.6.12
View basic information for a clustered collection (table)
View Help
db. Table name. Help ()
2. Query the number of data bars in the current collection
db. Table name. COUNT ()
3. View the size of the data space
db. Table name. DataSize ()
4. The database where the current aggregation collection resides
db. Table name. GETDB ()
5. Get the status of the current aggregation collection
db. Table name. Stats ()
6. Get the total size of the aggregation collection
db. Table name. TotalSize ()
7. View the aggregate collection storage space size
db. Table name. Storagesize ()
8. View Shard Version Information
db. Table name. Getshardversion ()
9. Renaming a Clustered collection
db. Table name. Renamecollection ("new name")
10. Delete the current clustered collection
db. Table name. Drop ()
Query operations
1. Querying All Records
db. Table name. Find () is equivalent to: select* from table name; The default is 20 records per page, and if not, you can query the next page of data with it iteration commands. Note: Type the IT command cannot take ";"
2. The query results filter out duplicate data in a field and then display it
db. Table name. DISTINCT ("field name") Example:> db.student.distinct ("Age") [20, 40] Note: The data in the age field in the student table is removed and displayed
3. Querying the AGE=22 data
db. Table name. Find ({"Age": 22}) Example:> Db.student.find ({"Age": +}) {"_id": ObjectId ("5740dcb29bc83e10802f1cd8"), "name": " Kity "," age ": +," gender ":" Womand "}
4. Querying the AGE>22 data
Greater than sign $GT > db.student.find ({"Age": {$gt: +}}) {"_id": ObjectId ("5740c1419bc83e10802f1cd6"), "name": "Tom", "age": 23, "Gender": "Male"} {"_id": ObjectId ("5740dc369bc83e10802f1cd7"), "name": "Jerry", "Age": $, "gender": "Male", "Guoji ":" China "} {" _id ": ObjectId (" 5742263773344acd707888ba ")," name ":" Gu Zenghui "," age ": +," gender ":" Male "," Course ":" Linux "}
5.
MongoDB Database Basic Operations