當前位置: 首頁>>代碼示例>>Java>>正文


Java MongoException.printStackTrace方法代碼示例

本文整理匯總了Java中com.mongodb.MongoException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java MongoException.printStackTrace方法的具體用法?Java MongoException.printStackTrace怎麽用?Java MongoException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mongodb.MongoException的用法示例。


在下文中一共展示了MongoException.printStackTrace方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: store

import com.mongodb.MongoException; //導入方法依賴的package包/類
@Override
public void store(gr.iti.mklab.simmo.core.Object object) throws IOException {
    try {

        if (object instanceof Image) {
            dao.userDAO.save(object.getContributor());
            dao.imageDAO.save((Image) object);
        } else if (object instanceof Video){ 
            dao.userDAO.save(object.getContributor());
            dao.videoDAO.save((Video) object);
        }
        else if (object instanceof Webpage) {
        	dao.saveWebpage((Webpage) object);
        }
        else {
            dao.savePost((Post) object);
        }
    } catch (MongoException e) {
        e.printStackTrace();
        logger.error("Storing item " + object.getId() + " failed.");
    }
}
 
開發者ID:MKLab-ITI,項目名稱:simmo-stream-manager,代碼行數:23,代碼來源:MongoDbStorage.java

示例2: connection

import com.mongodb.MongoException; //導入方法依賴的package包/類
public static void connection() {
	try {

		DB db = (new MongoClient("localhost", 27017)).getDB("Questions");

		DBCollection coll = db.getCollection("Questions");

		BasicDBObject query = new BasicDBObject();
		query.put("id", 1001);
		DBCursor cursor = coll.find(query);
		while (cursor.hasNext()) {
			System.out.println(cursor.next());
		}
	} catch (MongoException e) {
		e.printStackTrace();
	}
}
 
開發者ID:Arquisoft,項目名稱:Trivial_i1a,代碼行數:18,代碼來源:Connection.java

示例3: getLastRecord

import com.mongodb.MongoException; //導入方法依賴的package包/類
public static DBObject getLastRecord(DBCollection collection, Date startDate, Date endDate) {
	DBObject lastone = null;
	try {
		BasicDBObject searchQuery = new BasicDBObject();
		QueryBuilder qb = new QueryBuilder();
		qb.put("Date").greaterThanEquals(startDate).lessThanEquals(endDate);
		searchQuery.putAll(qb.get());
		DBCursor cursor = collection.find(searchQuery);
		
		while (cursor.hasNext()) {

			lastone = cursor.next();
		}
		

	} catch (MongoException e) {
		e.printStackTrace();

	}
	return lastone;
}
 
開發者ID:eBay,項目名稱:mTracker,代碼行數:22,代碼來源:Connector.java

示例4: canConnect

import com.mongodb.MongoException; //導入方法依賴的package包/類
public boolean canConnect() {
    try {
        mongoTemplate.getDb().getStats();
    }
    catch (MongoException ex) {
        ex.printStackTrace();
        return false;
    }

    return true;
}
 
開發者ID:omacarena,項目名稱:only-short-poc,代碼行數:12,代碼來源:MyMongoRepository.java

示例5: connection

import com.mongodb.MongoException; //導入方法依賴的package包/類
public static void connection(String contentToTransform) {
try {
Mongo conn = new Mongo();

DB db = conn.getDB("Questions");
	
DBCollection coll = db.getCollection("Questions");

BasicDBObject query = new BasicDBObject();

query.put("question", 1);

coll.createIndex(query, "question", true);

DBCursor cursor = coll.find(query);

BasicDBList list= (BasicDBList) JSON.parse(contentToTransform);

for(Object obj:list){
	coll.insert((DBObject)obj);
}

while (cursor.hasNext()) {
System.out.println(cursor.next());
}
} catch (MongoException  e) {
e.printStackTrace();
}
}
 
開發者ID:Arquisoft,項目名稱:Trivial_i1a,代碼行數:30,代碼來源:Connection.java

示例6: write

import com.mongodb.MongoException; //導入方法依賴的package包/類
public boolean write(TrendingTopics topics) {
	try {
		collection.insert(MongoUtils.trendingTopicsToDBObject(topics));
		return true;
	} catch (MongoException ex) {
		ex.printStackTrace();
	}
	return false;
}
 
開發者ID:sociam,項目名稱:trends-observatory,代碼行數:10,代碼來源:MongoWriter.java

示例7: connectCollection

import com.mongodb.MongoException; //導入方法依賴的package包/類
public static DBCollection connectCollection(DB db,String collectionname) {

		try {
			 DBCollection collection = db.getCollection(collectionname);
			 return collection;

		} catch (MongoException e) {
			e.printStackTrace();
		}
		return null;
	}
 
開發者ID:eBay,項目名稱:mTracker,代碼行數:12,代碼來源:Connector.java

示例8: getMovingAverage

import com.mongodb.MongoException; //導入方法依賴的package包/類
public static double getMovingAverage(DBCollection collection, String field, Date startDate, Date endDate) {
	double weekSum = 0;
	DBObject record = null;		
	int count = 0;
	try {
		BasicDBObject searchQuery = new BasicDBObject();
		QueryBuilder qb = new QueryBuilder();
		qb.put("Date").greaterThanEquals(startDate).lessThanEquals(endDate);
		searchQuery.putAll(qb.get());		
		DBCursor cursor = collection.find(searchQuery);
		
		while(cursor.hasNext()) {
			record = cursor.next();
			DBObject dbo = (DBObject) record.get("Data");
			Set<String> keySet = dbo.keySet();
			
			for(String keyName : keySet) {
				if (field.equals(keyName)) {
					count++;
					Object keyValue = dbo.get(keyName);
					double keyValueNum = 0;
					if (keyValue instanceof Integer) {
						int intValue = (Integer) keyValue;
						keyValueNum = Double.parseDouble("" + intValue);
					} else if (keyValue instanceof Double) {
						keyValueNum = (Double) keyValue;
					}
					weekSum += keyValueNum;
				}
			}
		}
	} catch (MongoException e) {
		e.printStackTrace();
	}	
	DAYS = count;
	return weekSum * 1.0 / count;
}
 
開發者ID:eBay,項目名稱:mTracker,代碼行數:38,代碼來源:Connector.java

示例9: TestMongoDBDatastoreProvider

import com.mongodb.MongoException; //導入方法依賴的package包/類
public TestMongoDBDatastoreProvider(){
	try {
		mongo = new MongoClient("localhost", 27017);
	} catch (MongoException e) {
		e.printStackTrace();
	}
	
	getMorphia().map(Person.class);
	getMorphia().map(Address.class);
}
 
開發者ID:EsfingeFramework,項目名稱:querybuilder,代碼行數:11,代碼來源:TestMongoDBDatastoreProvider.java

示例10: main

import com.mongodb.MongoException; //導入方法依賴的package包/類
@SuppressWarnings({ "resource", "deprecation" })
public static void main(String[] args) {
	try {
		/**** Connect to MongoDB ****/
		// Since 2.10.0, uses MongoClient
		MongoClient mongo = new MongoClient("localhost", 27017);

		/**** Get database ****/
		// if database doesn't exists, MongoDB will create it for you
		DB db = mongo.getDB("test");

		/**** Get collection / table from 'test' ****/
		// if collection doesn't exists, MongoDB will create it for you
		DBCollection table = db.getCollection("user");

		/**** Insert ****/
		// create a document to store key and value
		BasicDBObject document = new BasicDBObject();
		document.put("name", "ravindra");
		document.put("age", 30);
		document.put("createdDate", new Date());
		table.insert(document);

		/**** Find and display ****/
		BasicDBObject searchQuery = new BasicDBObject();
		searchQuery.put("name", "ravindra");

		DBCursor cursor = table.find(searchQuery);

		System.out.println("Finding a saved Object ....");
		while (cursor.hasNext()) {
			System.out.println(cursor.next());
		}
		System.out.println("Finding a saved Object Done ....");

		/**** Update ****/
		// search document where name="mkyong" and update it with new values
		BasicDBObject query = new BasicDBObject();
		query.put("name", "ravindra");

		BasicDBObject newDocument = new BasicDBObject();
		newDocument.put("name", "ravindra-updated");

		BasicDBObject updateObj = new BasicDBObject();
		updateObj.put("$set", newDocument);

		table.update(query, updateObj);

		/**** Find and display ****/
		BasicDBObject searchQuery2 = new BasicDBObject().append("name", "ravindra-updated");

		DBCursor cursor2 = table.find(searchQuery2);

		System.out.println("Finding an updated Object ....");
		while (cursor2.hasNext()) {
			System.out.println(cursor2.next());
		}
		System.out.println("Finding an updated Object Done ....");

		/**** Done ****/
		System.out.println("Done");
	} catch (MongoException e) {
		e.printStackTrace();
	}

}
 
開發者ID:CityOfNewYork,項目名稱:CROL-WebApp,代碼行數:67,代碼來源:MondoDbTest.java


注:本文中的com.mongodb.MongoException.printStackTrace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。