티스토리 뷰
설치
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
설정
Shell
$ mongo
> show dbs
admin 0.000GB
local 0.000GB
> use school_db
switched to db school_db
> db
school_db
> db.createUser({user: "principal", pwd: "123", roles: ["readWrite", "dbAdmin"]});
Successfully added user: { "user" : "principal", "roles" : [ "readWrite", "dbAdmin" ] }
> db.createCollection('students');
{ "ok" : 1 }
> show collections
students
> db.students.insert({name: 'Mike', age: 23, grade: "A"});
WriteResult({ "nInserted" : 1 })
> db.students.find();
{ "_id" : ObjectId("5a68aa36cc35afef83998952"), "name" : "Mike", "age" : 23, "grade" : "A" }
> db.students.insert([{name: 'Michael', age: 41, grade: "B+"},
... {name: 'Victor', age: 33, grade: "A+"},
... {name: 'Josh', age: 28, grade: "C+"}]);
BulkWriteResult({
"writeErrors" : [ ],
"writeConcernErrors" : [ ],
"nInserted" : 3,
"nUpserted" : 0,
"nMatched" : 0,
"nModified" : 0,
"nRemoved" : 0,
"upserted" : [ ]
})
> db.students.find();
{ "_id" : ObjectId("5a68aa36cc35afef83998952"), "name" : "Mike", "age" : 23, "grade" : "A" }
{ "_id" : ObjectId("5a68aaf9cc35afef83998953"), "name" : "Michael", "age" : 41, "grade" : "B+" }
{ "_id" : ObjectId("5a68aaf9cc35afef83998954"), "name" : "Victor", "age" : 33, "grade" : "A+" }
{ "_id" : ObjectId("5a68aaf9cc35afef83998955"), "name" : "Josh", "age" : 28, "grade" : "C+" }
> db.students.find().pretty();
{
"_id" : ObjectId("5a68aa36cc35afef83998952"),
"name" : "Mike",
"age" : 23,
"grade" : "A"
}
{
"_id" : ObjectId("5a68aaf9cc35afef83998953"),
"name" : "Michael",
"age" : 41,
"grade" : "B+"
}
{
"_id" : ObjectId("5a68aaf9cc35afef83998954"),
"name" : "Victor",
"age" : 33,
"grade" : "A+"
}
{
"_id" : ObjectId("5a68aaf9cc35afef83998955"),
"name" : "Josh",
"age" : 28,
"grade" : "C+"
}
> db.students.remove({});
WriteResult({ "nRemoved" : 4 })
> db.students.find().pretty();
> db.dropDatabase()
{ "dropped" : "school_db", "ok" : 1 }
'Programming > MongoDB' 카테고리의 다른 글
pymongo cursor에서 특정 field가 존재하는지 확인하는 코드 (0) | 2017.10.23 |
---|---|
pymongo cursor를 json으로 변환하기 (0) | 2017.10.23 |
MongoDB to Elasticsearch (0) | 2017.10.23 |
- Total
- Today
- Yesterday
- kubernetes
- MacOS
- Ansible
- git
- Python
- boot2docker
- IntelliJ
- pycharm
- Redis
- Spring Boot
- ansible-container
- 은전한닢
- Paw
- PIP
- GCP
- docker-machine
- scrapy
- TDD
- zsh
- mecab
- PubSub
- spring #lombok
- AWS
- docker
- Elasticsearch
- X-Pack
- MongoDB
- pymongo
- xpath
- Netty
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |