본문 바로가기

개발/db

[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의 순서로 연산

함수 말고 세 번째 argument에서 option으로 사용 가능

ex)

db.collection('grades').find({쿼리},{projection}, {'skip': 1, 'limit': 4, 'sort': {['grade': 1], ['name': -1]}});



hw 2.1

csv파일을 import 시킬 때. db이름은 weather, collection은 data

csv파일의 첫 line이 filed라면 --headerline 사용..

mongoimport --type csv --headerline weather_data.csv -d weather -c data