Iterate over large collection in MongoDB via spring-data

前端 未结 7 2042
误落风尘
误落风尘 2021-01-31 17:18

Friends!

I am using MongoDB in java project via spring-data. I use Repository interfaces to access data in collections. For some processing I need to iterate over all el

7条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 17:51

    you can still use mongoTemplate to access the Collection and simply use DBCursor:

         DBCollection collection = mongoTemplate.getCollection("boundary");
         DBCursor cursor = collection.find();        
         while(cursor.hasNext()){
             DBObject obj = cursor.next();
             Object object =  obj.get("polygons");
             ..
          ...
         }
    

提交回复
热议问题