本文整理匯總了Java中com.mongodb.DBCursor.toArray方法的典型用法代碼示例。如果您正苦於以下問題:Java DBCursor.toArray方法的具體用法?Java DBCursor.toArray怎麽用?Java DBCursor.toArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mongodb.DBCursor
的用法示例。
在下文中一共展示了DBCursor.toArray方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getChatMessages
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
* @param channelId The Unique ID of the channel.
* @param limit The Integer limit of ChatMessages to load.
* @return Returns a List of ChatMessages for the ChatChannel.
*/
private List<ChatMessage> getChatMessages(UUID channelId, int limit) {
List<ChatMessage> listChatMessages = new LinkedList<>();
// Grab all the messages with the channel_id set to the one provided.
DBObject query = new BasicDBObject("channel_id", channelId);
DBCursor cursor = collectionMessages.find(query);
// Sort the list by timestamp so that the last messages appear first.
cursor.sort(new BasicDBObject("timestamp", -1));
cursor.limit(limit);
if(cursor.size() > 0) {
List<DBObject> listObjects = cursor.toArray();
Collections.reverse(listObjects);
for(DBObject object : listObjects) {
// Create the MongoDocument.
MongoChatMessage mongoChatMessage = new MongoChatMessage(collectionMessages, object);
// Create the container for the document.
ChatMessage chatMessage = new ChatMessage(mongoChatMessage);
// Add this to the list to return.
listChatMessages.add(chatMessage);
}
}
// Close the cursor to release resources.
cursor.close();
// Return the result list of messages for the channel.
return listChatMessages;
}
示例2: CollectTraceWikipedia
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public CollectTraceWikipedia(ActorRef analyse, ShellService shell) {
this.analyse = analyse;
this.sh = shell;
try {
//nbre de requettes sauvegardé par interval de 30 secondes
Mongo m = new Mongo();
DB db = m.getDB( "trace10" );
DBCollection collTime = db.getCollection("thirtyseconde");
DBCursor cursor = collTime.find().sort(new BasicDBObject( "debutdate" , 1 ));
this.list = cursor.toArray();
}
catch (Exception e) {
System.out.println(e.toString());
}
}
示例3: find
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public List<DBObject> find(BasicDBObject query){
DBCursor cursor = this.dbColl.find(query);
return cursor.toArray();
}