몽고디비3
for (var i = 1; i<=100; i++){
var myLng = baseLng + (Math.random() * diffLng);
var myLat = baseLat + (Math.random() * diffLat);
var myCategories = categories [Math.floor(Math.random() * categories.length)];
db.places.save({location :[myLng , myLat] , category : myCategories});}
인덱스를 작성한다
db.places.getIndexes()
db.places.ensureIndex({location:"2d" , category:1});
180 범위를 벗어나는 문서를 삭제
db.places.find({"location" : {$gt:180}})
Q) 편의점을 찾아보자.
db.places.find({category : "편의점"})
Q) 은행을 찾아보자.
db.places.find({category : "은행"})
Q) 커피를 찾아보자.
db.places.find({category : "커피"})
Q) 00 근처에 편의점 , 은행 커피중 가장 가까운 10개를 찾아보자.
db.place.find({location:{$near:[126.8988122, 37.4852754]}}).limit(10);
{ "_id" : ObjectId("60c80ede79b03fa907b33985"), "location" : [ 128.0627478471098, 49.27615986587696 ], "category" : "커피" }에서
가장 까운 5개의 편의점, 은행, 커피를 찾아보자.
db.places.find({"location" : {$near:[128.0627478471098, 49.27615986587696 ]}}).limit(5);
Q) 00 근처에서 근방 0.25거리에 있는 은행을 찾아보자.
db.places.find({"location" : {{$within:0.25}$near:[128.0627478471098, 49.27615986587696 ]}}},{category : "은행"})
Q) 00 근처에서 가장 멀리있는 편의점 3개를 찾아보자
Q) 00근처에서 가장 멀리있는 은행과의 가운데있는 지점의 편의점을 찾아보자.
[파일 다루기]
mongofiles <options> <connection-string> <command> <filename or _id>
- 일반적으로 mongodb 저장할 수 있는 문서의 크기 16MB 상한
- GridFS Mongo를 분할해서 (입출력)하기 위한 인터페이스이다.
Q) images 데이터베이스에 사진파일을 올리고 싶다
mongofiles -v -d images put 1.jpg
Q)fs.files에 있는 파일의 목록을 확인하고 id를 찾아서 fs.chunks에서 데이터를 확인하자.
db.fs.chunks.find({files_id: ObjectId("60c8401f83685bbba8007f20")})
db.fs.chunks.find({files_id: ObjectId("60c840c581fc3c98fb160b65")}) 게임 txt
db.fs.chunks.find({files_id: ObjectId("60c841a2094f5d1ac6b0fad6")}) js
목록확인
c:\Test>mongofiles -v -d images list