1 . Create a database that is named Foobar
Use Foobar
this Foobar the database was not actually created. Just in the MONGO cache.
!--[if GTE VML 1]> !--[If!vml]-->!--[endif]-->
But if you leave directly, the database will be MONGO deleted.
2. Now we Add a collection to the Foobar database and add a record to do something to keep it from being deleted
now it's used. Foobar . This db represents this database .
Db.persons.insert ({name: "ABCdef"})
The above code means to use the Foobar This database, add a Persons collection. added a record to persons. name=abcdef
3. Querying all the databases
Show DBS
The number that follows indicates the size of the database
4. Querying all documents in the current database
Show collections
the first document is persons
the second document is Indexes is automatically generated by the system
View system content in a document
Db.system.iindexes.find ()
Enquiry Persons all the data in the document
Db.persons.find ()
querying the first piece of data : can only query to the first piece of data
Db.persons.findOne () Note findOne O to capitalize
5. Update the contents of the document
put the first record Name=uspcat the record. Change into uspcat1111
Db.persons.update ({name: "Uspcat"},{$set: {name: "uspcat1111"}})
The preceding parameter is the modified condition, and the following parameter is the value to modify. MongoDB defaults to the first record
The re-query discovery record has been changed.
Defining Variables P The value is the first record of the query. then print p
var p =db.persons.findone ()
P
then through the variable P to modify the first record
Db.persons.update (p,{name: "uspcat000"})
Db.perons.findOne ()
adds a field to an existing record. MONGO can arbitrarily increase any type of field in a record
First , modify the value of the first record to age=1
Db.persons.update (P,{age:1})
and then update
Db.persons.update ({age:1},{$set: {name: "Hello.world"}})
The above code means that when the first record age=1 the time. Add Field name=hello.world
6. Delete data from a document
Db.persons.remove ( Modify Condition )
db.persons.remove ({age:2}) Delete age=2 the records
Query again. The record is gone.
From for notes (Wiz)
Basic use of the shell in MongoDB