本文整理匯總了Java中com.mongodb.DBCursor.count方法的典型用法代碼示例。如果您正苦於以下問題:Java DBCursor.count方法的具體用法?Java DBCursor.count怎麽用?Java DBCursor.count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mongodb.DBCursor
的用法示例。
在下文中一共展示了DBCursor.count方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAllIds
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public List<String> getAllIds(final Map<String, Object> conditions) {
DBObject query = new BasicDBObject(conditions);
DBCursor cursor = coll.find(query);
List<String> ids = new ArrayList<String>(cursor.count());
for (DBObject o : cursor) {
ids.add(o.get("_id").toString());
}
return ids;
}
示例2: getCacheEntry
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public CacheEntry getCacheEntry(String key, CacheEntry defaultValue) {
DBCursor cur = null;
DBCollection coll = getCollection();
BasicDBObject query = new BasicDBObject("key", key.toLowerCase());
// be sure to flush
flushInvalid(coll,query);
cur = coll.find(query);
if (cur.count() > 0) {
hits++;
MongoDBCacheDocument doc = new MongoDBCacheDocument((BasicDBObject) cur.next());
doc.addHit();
//update the statistic and persist
save(doc,0);
return new MongoDBCacheEntry(doc);
}
misses++;
return defaultValue;
}
示例3: testQueryCount
import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Test
public void testQueryCount(@Mocked final DBCursor cursor) {
final BasicDBObject filterObject = new BasicDBObject("key1", "value1");
new Expectations() {
{
logger.isLoggable(Level.FINE);
result = true;
logger.fine("queryCount: Querying database with query object " + filterObject);
cursor.count();
result = 3;
logger.fine("queryCount: found 3 assets.");
}
};
Deencapsulation.invoke(createTestBean(), "queryCount", filterObject);
}
示例4: findTokensByClientId
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) {
List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>();
DBObject query = new BasicDBObject(clientIdFieldName, clientId);
DBObject projection = new BasicDBObject(tokenFieldName, 1);
DBCursor cursor = null;
try {
cursor = getAccessTokenCollection().find(query, projection);
if (cursor.count() > 0) {
while (cursor.hasNext()) {
OAuth2AccessToken token = mapAccessToken(cursor.next());
if (token != null) {
accessTokens.add(token);
}
}
} else {
LOG.info("Failed to find access token for clientId {}", clientId);
}
return accessTokens;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例5: findTokensByUserName
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public Collection<OAuth2AccessToken> findTokensByUserName(String userName) {
List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>();
DBObject query = new BasicDBObject(usernameFieldName, userName);
DBObject projection = new BasicDBObject(tokenFieldName, 1);
DBCursor cursor = null;
try {
cursor = getAccessTokenCollection().find(query, projection);
if (cursor.count() > 0) {
while (cursor.hasNext()) {
OAuth2AccessToken token = mapAccessToken(cursor.next());
if (token != null) {
accessTokens.add(token);
}
}
} else {
LOG.info("Failed to find access token for username {}.", userName);
}
return accessTokens;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例6: findTokensByClientIdAndUserName
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public Collection<OAuth2AccessToken> findTokensByClientIdAndUserName(String clientId, String userName) {
List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>();
DBObject query = new BasicDBObject(clientIdFieldName, clientId).append(usernameFieldName, userName);
DBObject projection = new BasicDBObject(tokenFieldName, 1);
DBCursor cursor = null;
try {
cursor = getAccessTokenCollection().find(query, projection);
if (cursor.count() > 0) {
while (cursor.hasNext()) {
OAuth2AccessToken token = mapAccessToken(cursor.next());
if (token != null) {
accessTokens.add(token);
}
}
} else {
LOG.info("Failed to find access token for clientId {} and username {}.", clientId, userName);
}
return accessTokens;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例7: contains
import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Override
public boolean contains(String key) {
DBCollection coll = getCollection();
BasicDBObject query = new BasicDBObject();
query.put("key", key.toLowerCase());
DBCursor cur = coll.find(query);
return cur.count() > 0;
}
示例8: keys
import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Override
public List<String> keys() {
List<String> result = new ArrayList<String>();
DBCursor cur = qAll_Keys();
if (cur.count() > 0) {
while (cur.hasNext()) {
result.add(caster.toString(cur.next().get("key"),""));
}
}
return result;
}
示例9: find
import com.mongodb.DBCursor; //導入方法依賴的package包/類
private static ModulesContainer find(DBObject query, DBObject orderBy, Integer limit, Integer page) throws SinfonierException {
DBCollection collection = MongoFactory.getDB().getCollection(collectionName);
List<Module> list = new ArrayList<Module>();
DBCursor cursor;
if (limit != null) {
page = (page != null && page > 0) ? ((page-1)*limit) : 0;
} else {
page = null;
}
if (query == null) {
cursor = collection.find();
} else {
cursor = collection.find(query);
}
int totalModules = cursor.count();
if (orderBy != null) {
cursor = cursor.sort(orderBy);
}
if (page != null && page > 0) {
cursor.skip(page);
}
if (limit != null) {
cursor = cursor.limit(limit);
}
for (DBObject dbObject : cursor) {
list.add(new Module(dbObject));
}
return new ModulesContainer(list, totalModules);
}
示例10: find
import com.mongodb.DBCursor; //導入方法依賴的package包/類
private static TopologiesContainer find(DBObject query, DBObject orderBy, Integer limit, Integer page) throws SinfonierException {
DBCollection collection = MongoFactory.getDB().getCollection(getCollectionName());
List<Topology> list = new ArrayList<Topology>();
DBCursor cursor;
if (limit != null) {
page = (page != null && page > 0) ? ((page-1)*limit) : 0;
} else {
page = null;
}
if (query == null) {
cursor = collection.find();
} else {
cursor = collection.find(query);
}
int totalTopologies = cursor.count();
if (orderBy != null) {
cursor = cursor.sort(orderBy);
}
if (page != null && page > 0) {
cursor.skip(page);
}
if (limit != null) {
cursor = cursor.limit(limit);
}
for (DBObject dbObject : cursor) {
list.add(new Topology(dbObject));
}
return new TopologiesContainer(list, totalTopologies);
}
示例11: testFind
import com.mongodb.DBCursor; //導入方法依賴的package包/類
/**
* 查詢所有的用戶信息
*/
public void testFind() {
testInitTestData();
// find方法查詢所有的數據並返回一個遊標對象
DBCursor cursor = user.find();
while (cursor.hasNext()) {
print(cursor.next());
}
// 獲取數據總條數
int sum = cursor.count();
System.out.println("sum===" + sum);
}
示例12: run
import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Override
public void run() {
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket sender = context.socket(ZMQ.PUSH);
sender.setHWM(1);
sender.connect("tcp://localhost:5559");
while (!Thread.currentThread().isInterrupted()) {
try {
// Wait for fetched batch.
DBObject batch = queue.take();
logger.info("Sending batch: "+batch.get("jobId"));
DBCursor data = collection.find(new BasicDBObject()
.append("jobId", batch.get("jobId"))
.append("status", null));
int count = data.count();
while (data.hasNext()) {
logger.info("Sending batch item ("+(data.numSeen()+1)+"/"+count+"): jobId="+batch.get("jobId"));
DBObject doc = data.next();
sender.send(gson.toJson(doc), data.hasNext() ? ZMQ.SNDMORE : 0);
collection.remove(doc);
}
// Remove all references to this batch from DB.
// collection.findAndRemove(new BasicDBObject("jobId", batch.get("jobId")));
collection.remove(batch);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
sender.close();
context.term();
}
示例13: queryCount
import com.mongodb.DBCursor; //導入方法依賴的package包/類
private int queryCount(DBObject filterObject) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("queryCount: Querying database with query object " + filterObject);
}
DBCursor cursor = getAssetCollection().find(filterObject);
int count = cursor.count();
if (logger.isLoggable(Level.FINE)) {
logger.fine("queryCount: found " + count + " assets.");
}
return count;
}
示例14: findChildren
import com.mongodb.DBCursor; //導入方法依賴的package包/類
@Override
public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) {
LOG.debug(ACL, "Looking for children of object identity {}", parentIdentity);
DBObject query = queryByParentIdentity(parentIdentity);
DBObject projection = new BasicDBObject(objectIdFieldName, true);
DBCursor cursor = null;
try {
cursor = getAclCollection().find(query, projection);
if (cursor.count() == 0) {
LOG.debug(ACL, "No child object found for identity {}", parentIdentity);
return null;
}
LOG.trace(ACL, "Streaming cursor in order to retrieve child object identities");
List<ObjectIdentity> oids = new ArrayList<ObjectIdentity>();
while (cursor.hasNext()) {
oids.add(toObjectIdentity((DBObject) cursor.next().get(objectIdFieldName)));
}
return oids;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例15: obtenerPreguntaAleatoria
import com.mongodb.DBCursor; //導入方法依賴的package包/類
public static Result obtenerPreguntaAleatoria(String categoria) {
String resultJSON = "";
categoria = checkCategoria(categoria);
BasicDBObject consulta = new BasicDBObject();
consulta.put("categoria", categoria);
String coleccion = "preguntas";
DBCursor cursor = ejecutarConsulta(consulta, coleccion);
int maxIndex = cursor.count() - 1;
int posRandom = (int) (Math.random() * ((maxIndex - 0) + 1) + 0);
int i = 0;
while (cursor.hasNext()) {
DBObject preguntaJSON = cursor.next();
if (i == posRandom) {
resultJSON = preguntaJSON.toString();
break;
}
i++;
}
cursor.close();
resultJSON = ocultarRespuestaCorrecta(resultJSON);
return ok(resultados.render(resultJSON));
}