mongodb-- knowledge

 

 

A, sql database database difference nosql

 

 

 

Two, nosql database classification

 

1, key database

 

2, column-store database

 

3, document database

 

4, graph database

 

 

Third, start

Configuration environment variable

Start Service

mongod  --dbpath D:\MongoDB

 

Client server link

mongo ip:27017

 

show dbs see what database

 

 

 

 

show collections View database tables

 

Look-up table data

db.user.find()

and

DB . COL . Find ({ "by" : "novice Tutorial" , "title" : "MongoDB Tutorial" })

db.user.find({"age":{$lte:30,$gte:20}})

 

or

db.user.find({$or:[{"age":20},{"age":10}]})

 

Fuzzy query

db.user.find({name:/张/})

Beginning with Zhang

db.user.find({name:/^张/})

Specify the columns in the query only query the name column

db.user.find({},{name:1})

Sequence

Ascending

db.user.find({}).sort({"age":1})

Descending

db.user.find({}).sort({"age":-1})

5 paging query data

db.user.find({}).limit(5)

The first query from a few to a few first

From Article 3 Start Query 5

db.user.find().skip(2).limit(5)

db.user.find().skip(0).limit(5)

 

Number of inquiries

db.user.find().count()

 

Update table data

db.col.update({'title':'MongoDB 教程'},{$set:{'title':'MongoDB'}})

The first condition without change

db.user.update({},{$set:{'age':5}})

Without replacement set

db.col.update({'title':'MongoDB 教程'},{'title':'MongoDB'})

 

 

Delete table collection

db.user.drop()

Delete Database

db.dropDatabase()

Delete data delete data equal to the age of 30

db.user.remove({"age",30})

 

Query index collection

db.user.getIndexes()

 

Delete Index

db.user.dropIndex({"name":1})

 

View query execution

db.user.find().explain("executionStats")

Set the index to set the index name column

db.user.ensureIndex({"name":1})

 

Guess you like

Origin www.cnblogs.com/jentary/p/12333353.html