note in class.txt 844 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
//See manual of mongod
man mongod

//Set path
mkdir -p ~/mongodbdir
mongod --dbpath ~/mongodbdir

//Switch to myappdb collection
use myappdb

//Insert data to collection ("")
db.students.insert({name:"ป้อม",age:20})
db.students.insert({name:"Yos",age:21,gpa:3.5})


//Find all data in collections
db.students.find()
db.students.find().pretty()	--> in beautiful format


JSON หรือ Java Script Object Notation 

pkill mongod --> To kill mongod process

db.students.find({name:"Yos"}).pretty()

//Search data ที่มีตัว Y
db.students.find({name:/Y/}).pretty()

//Delete data name "Yeti"
 db.students.remove({name:"Yeti"})

//Update data
db.students.update({name:"ป้อม"},{$set:{age:23}})
//Multi update datadb.students.update({name:"ป้อม"},{$set:{age:23,name:"ป้อมป้อม"}})