protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		JSONObject jb = new JSONObject();
		InputStreamReader reader = 
				new InputStreamReader(request.getInputStream(), "utf-8"); 
		String receivedString = "";
		char[] buff = new char[1024]; 
		int length = 0; 
		while ((length = reader.read(buff)) != -1) 
		{ 
			receivedString = new String(buff, 0, length); 
		}
		try {
			JSONObject receivedObject = new JSONObject(receivedString);
			String userId = receivedObject.getString("userId");
			JSONArray friends = receivedObject.getJSONArray("friends");
			try{
				Mongo mongo =new Mongo();
				DB scheduleDB = mongo.getDB("schedule");
				DBCollection groupCollection = scheduleDB.getCollection("group_"+userId);
				for(int i = 0; i < friends.length(); i++){
					DBObject ifExist = new BasicDBObject();
					ifExist.put("groupName", "All friends");
					ifExist.put("member", friends.getString(i));
					if(!groupCollection.find(ifExist).hasNext()){
						DBObject friend = new BasicDBObject();
						String memberId = friends.getString(i);
						friend.put("member", memberId);
						DBObject member = new BasicDBObject();
						member.put("$push", friend);
						DBObject query = new BasicDBObject();
						query.put("groupName", "All friends");
						groupCollection.update(query,member);
						DBCollection eventCollection = scheduleDB.getCollection("event_"+userId);
						DBCursor eventCur = eventCollection.find();
						int count = 0;
						while(eventCur.hasNext() && count <10){
							DBObject eventObject = eventCur.next();
							String eventId = eventObject.get("_id").toString();
							String updateTime = eventObject.get("updateTime").toString();
							DBObject socialObject = new BasicDBObject();
							socialObject.put("userId", userId);
							socialObject.put("eventId", eventId);
							socialObject.put("updateTime", updateTime);
							DBCollection socialCollection = 
									scheduleDB.getCollection("social_"+memberId);
							socialCollection.save(socialObject);
						}
						
					}			
				}
			}catch(MongoException e){
				jb.put("result", Primitive.DBCONNECTIONERROR);
				e.printStackTrace();
			}
			jb.put("result", Primitive.ACCEPT);
		} 
		catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		PrintWriter writer = response.getWriter();
		writer.write(jb.toString());
		writer.flush();
		writer.close();
	}