package Util;

import java.net.UnknownHostException;

import com.mongodb.DB;
import com.mongodb.MongoClient;

public class MangoDBTest {
	public static void main(final String[] args) throws UnknownHostException
	{
		MongoClient mongoClient = new MongoClient("localhost" , 27017);
		DB db = mongoClient.getDB(MongoDBUtil.DBNAME);
		//DBCollection users = db.getCollection(MongoDBUtil.USERS_COLLECTION_NAME);
		/*BasicDBObject document = new BasicDBObject();
		document.put(MongoDBUtil.USER_FNAME_FIELDNAME, "Dan");
		document.put(MongoDBUtil.USER_LNAME_FIELDNAME, "Jiang");
		document.put(MongoDBUtil.USER_EMAIL_FIELDNAME, "djiang1@student.gsu.edu");
		document.put(MongoDBUtil.USER_PASSWORD_FIELDNAME, "djiang");
		document.put(MongoDBUtil.USER_ADDRESS1_FIELDNAME, "1104 Rutherford Glen Circle");
		document.put(MongoDBUtil.USER_ADDRESS2_FIELDNAME, "");
		document.put(MongoDBUtil.USER_CITY_FIELDNAME, "Atlanta");
		document.put(MongoDBUtil.USER_STATE_FIELDNAME, "GA");
		document.put(MongoDBUtil.USER_COUNTRY_FIELDNAME, "U.S");
		document.put(MongoDBUtil.USER_PHONE_FIELDNAME, "678-790-4375");
		document.put(MongoDBUtil.USER_ZIP_FIELDNAME, "30340");
		document.put(MongoDBUtil.USER_RECEIPTS_FIELDNAME, djsonDBUtil.getReceipts("song.x.guo@oracle.com"));
		
		System.out.println(document.toString());
		users.insert(document);*/
		
		/*BasicDBObject searchQuery = new BasicDBObject();
		searchQuery.put(MongoDBUtil.USER_EMAIL_FIELDNAME, "djiang1@student.gsu.edu");
		DBCursor cursor = users.find(searchQuery);
		while(cursor.hasNext())
		{
			DBObject user = cursor.next();
			BasicDBList receipts = (BasicDBList) user.get(MongoDBUtil.USER_RECEIPTS_FIELDNAME);
			for(int i=0; i<receipts.size(); ++i)
			{
				BasicDBObject receipt = (BasicDBObject)receipts.get(i);
				System.out.println(receipt.toString());
			}
		}*/
		
		/*DBCollection merchants = db.getCollection(MongoDBUtil.MERCHANTS_COLLECTION_NAME);
		JSONArray ms = MongoDBUtil.getMerchants();
		for(int i=0; i<ms.size(); ++i)
		{
			JSONObject json = (JSONObject)ms.get(i);
			BasicDBObject merchant = new BasicDBObject();
			merchant.put(MongoDBUtil.MERCHANT_ID_FIELDNAME, json.get(MongoDBUtil.MERCHANT_ID_FIELDNAME).toString());
			merchant.put(MongoDBUtil.MERCHANT_NAME_FIELDNAME, json.get(MongoDBUtil.MERCHANT_NAME_FIELDNAME).toString());
			merchant.put(MongoDBUtil.MERCHANT_CATEGORY_FIELDNAME, json.get(MongoDBUtil.MERCHANT_CATEGORY_FIELDNAME).toString());
			merchant.put(MongoDBUtil.MERCHANT_ADDRESS1_FIELDNAME, json.get(MongoDBUtil.MERCHANT_ADDRESS1_FIELDNAME).toString());
			merchant.put(MongoDBUtil.MERCHANT_ADDRESS2_FIELDNAME, json.get(MongoDBUtil.MERCHANT_ADDRESS2_FIELDNAME).toString());
			merchant.put(MongoDBUtil.MERCHANT_CITY_FIELDNAME, json.get(MongoDBUtil.MERCHANT_CITY_FIELDNAME).toString());
			merchant.put(MongoDBUtil.MERCHANT_STATE_FIELDNAME, json.get(MongoDBUtil.MERCHANT_STATE_FIELDNAME).toString());
			merchant.put(MongoDBUtil.MERCHANT_ZIP_FIELDNAME, json.get(MongoDBUtil.MERCHANT_ZIP_FIELDNAME).toString());
			merchant.put(MongoDBUtil.MERCHANT_PHONE_FIELDNAME, json.get(MongoDBUtil.MERCHANT_PHONE_FIELDNAME).toString());
			System.out.println(merchant.toString());
			merchants.insert(merchant);
		}*/
		mongoClient.close();
	}
}
