1. 程式人生 > >mongodb批量插入插入資料

mongodb批量插入插入資料

@Test
	public void test200() throws Exception{
		MongoControl mongo = new MongoControl("smg", "t_schedule");
		List<DBObject> list = new ArrayList<DBObject>();  
		for(int i = 10000001; i <= 100000000; i++) {
			DBObject basic = new BasicDBObject();
			basic.put("id", "10086"+i);  
			basic.put("startTime", StringUtil.getCurrentAllDate());  
			basic.put("endTime", StringUtil.getCurrentAllDate());  
			basic.put("fileId", i);  
			list.add(basic);  
			if(i!=0 && i % 10000 == 0){
				System.out.println(i);
				mongo.batchInsert(list);
				list.clear();
			}
		}
	}