Some basic operation of MongoDB

Some of the basic operation MongoDB (CRUD and Index)


When I started to see the MongoDB is very puzzled

Collection in the end is what (actually a table) and Row and Column are called the document and filed

MongoDB syntax similar to js, ​​SQL is much more than intuitive (I really hate XML)

By insert
db.testmongo.insert({"name":"mundo",
description: "rookie programer"
})
Delete remove
>db.testmongo.remove({'title':'mundo'})
改 update
>db.testmongo.update({'title':'mundo'},{$set:{'title':'Mundo'}})
# 如果需要改多条相同的语句的话,把multi参数设置成true
>db.testmongo.update({'title':'mundo'},{$set:{'title':'Mundo'}}),{multi:true})
Charles find
db.testmongo.find().pretty()

Index

May be in a database, the most interesting thing is that the index, which greatly improves the efficiency of the query

In such a relational database which MySQL, index using a B + tree data structure to be maintained (similar to the idea of separation of hot and cold data)

In MongoDB inside, we use ensureIndex () method to create an index (speak to will go, NOSQL not entirely without a shadow of a relational database)

db.testmongo().ensureIndex({"title":1})
#1意味着升序

Of course, you can create "composite index" (this is the name for a relational database), here called the Multiple-Field Index

Guess you like

Origin www.cnblogs.com/QuixoteY/p/11127633.html