本文整理汇总了Java中com.mongodb.DBCollection.count方法的典型用法代码示例。如果您正苦于以下问题:Java DBCollection.count方法的具体用法?Java DBCollection.count怎么用?Java DBCollection.count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.DBCollection
的用法示例。
在下文中一共展示了DBCollection.count方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: snapshotCount
import com.mongodb.DBCollection; //导入方法依赖的package包/类
@Override
public <T extends Model> Long snapshotCount(Class<T> modelClass, Map<String, Object> filter) {
if (modelClass == null)
throw new DaoException("Model class cannot be null");
if (filter == null)
filter = EMPTY_FILTER;
DBObject dbObject = buildQueryFilter(modelClass, filter, null);
DBCollection col = collection(modelClass, true);
Long count = col.count(dbObject);
if (count != null) {
app.setQueryMetadata(QueryMetadata.builder().count(count).build());
}
return count;
}
示例2: count
import com.mongodb.DBCollection; //导入方法依赖的package包/类
/**
* 分页查询,count
* @param dbName
* @param collName
* @param query
* @return
*/
public static long count(String dbName, String collName, DBObject query) {
DBCollection collection = getCollection(dbName, collName);
if (collection != null) {
return collection.count(query);
}
return -1;
}
示例3: getQueryCount
import com.mongodb.DBCollection; //导入方法依赖的package包/类
private long getQueryCount(DBCollection collection) {
DBObject query = getQuery();
if (null == query) {
return collection.count();
} else {
return collection.count(query);
}
}
示例4: readPatternsFromMongo
import com.mongodb.DBCollection; //导入方法依赖的package包/类
private List<PatternReference> readPatternsFromMongo() {
// TODO: Ideally this would do something in a more streaming manner, as there are likely to
// be lots of examples
DBCollection collection = mongo.getDB().getCollection(patternCollection);
List<PatternReference> patterns = new ArrayList<>((int) collection.count());
DBCursor cursor = collection.find();
while (cursor.hasNext()) {
DBObject o = cursor.next();
// TODO: We don't currently use types (entity source target) but we could do
// at least to output something to the relationship type filter
BasicDBList list = (BasicDBList) o.get("words");
List<Word> tokens = list.stream().map(l -> {
BasicDBObject dbo = (BasicDBObject) l;
String pos = dbo.getString("pos");
String lemma = dbo.getString("lemma");
// Fall back to actual text if no lemma
if (lemma == null) {
lemma = dbo.getString("text");
}
return new Word(lemma.trim().toLowerCase(), WordNetUtils.toPos(pos));
}).filter(w -> w.getPos() != null)
.collect(Collectors.toList());
patterns.add(new PatternReference(o.get("_id").toString(), tokens));
}
return patterns;
}
示例5: onRootAccess
import com.mongodb.DBCollection; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody Result onRootAccess() {
DBCollection collection = mongoTemplate.getCollection("test");
long count = collection.getCount();
log.info("Object count in 'test' collection before insert: " + count + "<br/> Inserting one object.<br/>");
BasicDBObject dBObject = new BasicDBObject();
dBObject.put("hello", "world");
collection.insert(dBObject);
count = collection.count();
log.info("Object count in test collection after insert:" + count);
Result result = new Result();
List<DBObject> dbObjects = new ArrayList<DBObject>();
DBCursor cursor = collection.find();
while (cursor.hasNext()) {
com.mongodb.DBObject obj = cursor.next();
final String value = (String) obj.get("hello");
DBObject object = new DBObject();
object.setKey("hello");
object.setValue(value);
dbObjects.add(object);
}
result.setDbObjects(dbObjects);
result.setStatus(
"Successfully accessed Mongodb service. Retrieving the data object inserted in test collection.");
collection.drop();
return result;
}
示例6: get
import com.mongodb.DBCollection; //导入方法依赖的package包/类
@Override
public Object get(String key) throws PageException {
DBCollection coll = db.getCollection(key);
if(coll.count()!=0 || containsKey(key)) return toCFML(coll);
throw exp.createExpressionException("key ["+key+"] doesn't exist ");
}
示例7: count
import com.mongodb.DBCollection; //导入方法依赖的package包/类
private static long count(DBObject query) {
DBCollection collection = MongoFactory.getDB().getCollection(collectionName);
return collection.count(query);
}
示例8: count
import com.mongodb.DBCollection; //导入方法依赖的package包/类
private static long count(DBObject query) {
DBCollection collection = MongoFactory.getDB().getCollection(getCollectionName());
return collection.count(query);
}