Basic operating commands of mongodb
= = basic operation command of mongodb =
DDL operation =
Create the schema: use Schema; create an object in Schema to db.createCollection ("CollectionName"). Equivalent to create database DBName
Create a collection: db.createCollection ("test"); equivalent to the creation table create table TableName () in DBMS
Showcase architecture: show dbs; is equivalent to show databases in mysql
Show the number of collections: show collections; show tables
Delete the current architecture: use Schema; db.dropDatabase (); drop database DBName
Modify the collection name: db.CollectionName.renameCollection ("NewName"); similar to alter table oldTable rename to NewTable in mysql
Delete collection: db.collections.drop (); similar to drop table tableName in mysql
View the current DB:db
User-related actions =
Add user: db.addUser ("UserName", "PWD")
Verify that the user has been added successfully: db.auth ("UserName", "PWD")
Delete user: db.removUsers ("testUser")
Permission related:
Http://blog.itpub.net/22664653/viewspace-715617/
DML operation =
Query collection: db.CollectionName.find ({}); equivalent to select * from TableName
Equality condition query: db.CollectionName.find ({key01:value01}); equivalent to select * from TableName where key01=value01
Different values of the query field (deduplicated): db.CollectionName.distinct ("Key") is similar to select distinct (key) from table
Fuzzy query: db.collections.find ({key:/ang/}); select * from tableName where key like'% ang%'
: db.collections.find ({key:/ ^ ang /}); select * from tableName where key like 'ang%'
: db.collections.find ({key:/g$/}); select * from tableName where key like'% ang'
Query the specified list: db.collections.find ({}, {key01:false,key02:true,key03:true}); select key02,key03 from tableName
Range lookup: db.collections.find ({key01: {$gt:20}}); select * from tableName where key01 > 20
: db.collections.find ({key01: {$lge:20}}); select * from tableName where key01 > = 20
: db.collections.find ({key01: {$lt:20}}); select * from tableName where key01 < 20
: db.collections.find () {key01: {$lte:20}}; select * from tableName where key01 = 24 and key01