목록전체 글 (762)
우노
1. EC2 Instance 접속 ssh -i "Ec2-for-documentDB-access.pem" ec2-user@ec2-54-89-18-159.compute-1.amazonaws.com 2. MongoDB shell 설치 sudo vi /etc/yum.repos.d/mongodb-org-3.6.repo [mongodb-org-3.6] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.6/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc Mongodb shell, Mongdb Tool (..
Create/Read/Update/Delete Operations Insert db.collection.insertOne( { item: "notebook", qty: 50, tags: ["red", "blank"], dim_cm: [ 14, 21 ], status: "D" }, ) db.collection.insertMany([ { item: "notebook", qty: 50, tags: ["red", "blank"], dim_cm: [ 14, 21 ], status: "D" }, { item: "paper", qty: 100, tags: ["red", "blank", "plain"], dim_cm: [ 14, 21 ], status: "A" }, { item: "planner", qty: 75, t..
Condition AND 조건 db.collection.find({ status : "A", item : "paper" }) pretty ( 데이터를 보기 쉽게 ) db.collection.find({ status : "A", item : "paper" }).pretty() $ pedicate (속성) $and, $or, $in, $lt, $gt.. 등 $and condition db.collection.find({ $and : [ {status : "A"}, {item : "paper"}] }) $or condition status가 A이거나 qty가 60 이하인 것 어떤 상태에 들어갈 땐 항상 중괄호 db.collection.find({$or : [{status:"A"},{qty : {$lt : 60..
Array 요소 접근 find Array안에 해당 value가 포함만 돼 있어도 출력해준다! db.collection.find({ tags : "red" }) $in 해당 value 들 중 하나라도 들어가 있는 애들 출력! db.collection.find({ status : {$in : ["A", "D"]}}) $all 해당 요소가 모두 포함 된 것들을 출력! db.collection.find({ tags : {$all : ["red", "blank"]}}) $nin 해당 요소가 포함 안 된 것들을 출력! db.collection.find({ status : {$nin : ["A", "D"]}}) 해당 요소가 정확히 일치하는 것만 출력! db.collection.find({ tags : ["red", ..
Projection parameter find로 쿼리를 날릴 때 find의 파리미터는 다음과 같다. db.$(collection).find( {filter condition} , {projection parameter}) 각 파라미터는 중괄호로 구분한다. filter condition으로 도큐먼트를 뽑아낸 뒤 projection parameter로 원하는 도큐먼트를 걸러낸다. filter condition 내부 { field : , field : } status가 A인 것을 출력하고 item 과 status를 보여준다! db.collection.find({ status : "A"}, {item : 1, status : 1}) status가 A인 것을 출력하고 _id, status, instock 를 없애..
Cursor 커서 안에서 지속적으로 iteration하면서 보는 것! var cursor = db.collection.find() cursor.hasNext() cursor.next() cursor.objsLeftInBatch() cursor.next() cursor.objsLeftInBatch() iterate a Cursor var cursor = db.collection.find() while(cursor.hasNext()){ print(tojson(cursor.next())); } 도큐먼트 하나씩 출력 var cursor = db.collection.find() cursor.foreach(printjson) 배열로 변환 var cursor = db.collection.find() var curso..
Aggregation이란? Aggregation은 파이프라인으로 구성된다. Project : 한 번 걸러서 다음 operation으로 넘긴다. Match : 조건에 맞는 애들만 필터링한다. Limit, Skip : 제한 Group : 그룹화 Sort : 정렬 Aggregation은 각각의 operation들이 , 로 구분 돼 리스트형식으로 들어간다. db.products.aggregate([ {$match: ...}, {$group: ...}, {$sort: ...} ]) Match filtering을 뜻한다. { $match: { } } // aggregate의 match는 find와 동일한 결과! db.zipcodes.aggregate( [ {$match: {city: "GOSHEN"} } ] ) d..
tmux 란? tmux 는 '세션' 을 통해 terminal 화면을 여러개로 분할하거나, terminal 을 background 에서 영구적으로 실행되게 할 수 있습니다. 용어 session tmux 가 관리하는 가장 큰 단위로, 1 개 이상의 window 로 구성될 수 있습니다. 사용자는 session 에 attach/detach 를 할 수 있으며, detach 를 하더라도 session 은 background 에서 계속 실행되게 됩니다. window session 내에 존재하는 하나의 tab 을 의미하는 단위로서, window 를 전환하게 되면 tab 을 전환할 때 처럼 전체 화면이 전환됩니다. pane 한 window 내에 분할된 화면의 단위로서, 하나의 window 가 여러 개의 p..
1. 실습을 위한 파일 다운로드 wget http://media.mongodb.org/zips.json 2. 파일을 docker mongodb container 내부로 전송 mongodb container 내부에 tmp/zips.json이 생긴다. docker cp zips.json mongodb:/tmp/zips.json 3. mongodb container의 데이터를 mongodb에 삽입 collection 이름을 zipcodes로 설정! docker exec -it mongodb bash mongoimport --collection zipcodes --file /tmp/zips.json 4. mongodb 접속 후 데이터 들어갔는지 확인하기 mongodb.zipcodes.find( { } )
현재 컬렉션에 적용된 인덱스 확인하기 db.zipcodes.getIndexes() Index 만들기 db.zipcodes.createIndex( { pop : 1 } ) 속도 비교하기 // index가 돼 있으면 pop이 있는 도큐먼트만 본다! db.zipcodes.find({pop:100}).explain("executionStats") // 모든 도큐먼트 확인 -> pop이 있는 도큐먼트 찾기 -> 정렬 db.zipcodes.find({pop:100}).explain("executionStats") Compound Index 여러개의 키를 가지고 인덱스를 만드는 것 db.zipcodes.createIndex( { city : 1, pop : 1} ) Index 지우기 key or Value로 삭제 가..