본문 바로가기

개발/db

[mongodb] MongoDB university - week5 : aggregation framework https://university.mongodb.com/courses/10gen/M101JS/2015_May/courseware sql에서의 group by는 다음과 같다.몽고에서db.products.aggregate([{$group:{_id: "$manufacturer",num_products: {$sum: 1} //1씩 더한다. 가격같은필드를 더할때는 1대신 "$필드이름"}}]) pipeline ( collection->ㅁ($project)->ㅁ($match)->ㅁ($group)->ㅁ($sort)->result )위의 배열의 각 item이 pipeline의 단계(stage)이다$project는 document를 reshape.. 특정 필드를 선택해서 top으로 끌어올려 document를 reshape.. 더보기
[mongodb] MongoDB university - M101JS week4 : Indexes 몽고db Index Creation documents가 디스크에 저장될 때 특정한 순서가 없다.인덱스가 없는 경우에 쿼리를 하면 콜렉션안의 모든 document를 스캔히야 한다. document가 많으면 작업량이 상당하므로 index를 만드는 것이 좋다. 인덱스 만들기db.students.createIndex({"student_id": 1, "class_id": -1}); 인덱스보기db.students.getIndexes(); 인덱스삭제db.students.dropIndex({student_id: 1}) Multikey Indexesdb.foo.createIndex({a: 1, b:1}); - a, b가 둘다 배열이면 안 됨(??)db.foo.explain().find({a:1}); -자세하기보기(사용한.. 더보기
[mongodb] MongoDB university - M101JS week2 2/2 grades.json이라는 json파일을 mongodb에 course라는 db에 grades 라는 collection으로 import$ mongoimport -d course -c grades grades.json 두 번째 argument에서 return받고 싶은 filed설정 가능. projection이라고 함ex) grade만 표시하고 싶은 경우db.collection('grades').find({쿼리},/*option*/ {'grade': 1, '_id': 0}, callback); 쿼리에서 property를 접근할 때는 student.info.name 의 . 접근으로 가능 sort, skip, limit 의 함수를 쓸 때 순서에 상관 없이 sort skip limit의 순서로 연산함수 말고 세 번.. 더보기
[mongodb] MongoDB university - M101JS week2 1/2 $gt: greater than$gte: greater than, equal$lt: less than$lte: less than, equalex) db.users.find({score: {$lte: 100}}) $regex: 해당 string 포함$exists: 그 field가 존재 하는지$type: 그 field타입이 무엇인지ex) db.users.find({username: {$regex: 'a'}, email: { $exists: true}}): username에 a가 들어가면서 email 필드가 있을 때db.users.find({username: {$type: 2}}) : username이 string인 것을 찾을 때 $orex) db.users.find({$or: [ {쿼리}, {쿼리}]}) $.. 더보기
[mongodb] 실행 순서 1. 콘솔 프롬포트에서 몽고DB를 시작한다.mongod -dbpath 몽고DB데이터를둘자리/data/db 2. 몽고 DB 시동(데이터베이스 엔진을 시동)몽고를설치한자리/bin 의 mongod.exe 실행 3. 몽고DB 셸 시작mongo 더보기
[mongoDB] 비교 연산자 $gt: > 초과$gte: >= 이상$in: 배열 안에 값이 존재 할 때$lt: < 미만$lte: 더보기
[mongodb] mongolab으로 import 하는 법 json 파일을 import 하는 방법 shell에서>mongoimport -h ds012345.mongolab.com:56789 -d dbname -c collectionname -u dbuser -p dbpassword --file filename.json 유의할 점.위와 같은 명령어를 사용하려면 json 파일의 형태가 아래와 같아야 한다.{"_id": "allie", "name": "앨리"} {"_id": "noah", "name": "노아"} 만약 아래와 같이 json 형식의 json 파일을 import 하려면[{"_id": "allie", "name": "앨리"}, {"_id": "noah", "name": "노아"}] 명령어 뒤에 --jsonArray 를 붙여준다. 더보기
[mongodb] 시작 c:\mongoDB>mongod.exe실행되면새로운 cmd에서 연결c:\mongoDB>mongo 더보기
[mongodb] 개념 테이블 = collectionrow = document 더보기