mongodb 시작하기

$ sudo service mongod start

 

mongodb shell 시작

$ mongo

 

database 종류 확인

> show databases

 

database 사용(선택)

> use {database이름}

 

collection 종류 확인

(db 선택 이후)

> show collections

 

collection 제거

> db.{collection 이름}.drop()

 

document 추가

> db.{collection 이름}.insert({문서})

db.books.insert({"a":1})
WriteResult({ "nInserted" : 1 })

 

document bulk insert

> db.{collection 이름}.insert([{문서}])

db.books.insert([{"a":1},{"b": 1}])
BulkWriteResult({
"writeErrors" : [ ],
"writeConcernErrors" : [ ],
"nInserted" : 2,
"nUpserted" : 0,
"nMatched" : 0,
"nModified" : 0,
"nRemoved" : 0,
"upserted" : [ ]
})

 

document 찾기

> db.{collection 이름}.find({조건})

{조건}도 json 형태로 입력

 

document 지우기(조건 맞는 모든 document 지우기)

> db.{collection 이름}.remove({조건})

{조건}도 json 형태로 입력

 

document 지우기(조건 맞는 하나의 document 지우기)

> db.{collection 이름}.remove({조건}, true)

{조건}도 json 형태로 입력

'Development > Database' 카테고리의 다른 글

MongoDB에서 Connection Pool 구성 하기  (0) 2017.02.13
MongoDB Ubuntu에 설치하기  (0) 2017.02.10
MongoDB 에서 admin 만들기  (2) 2017.02.10

+ Recent posts