本文整理汇总了Java中com.mongodb.client.MongoCollection.count方法的典型用法代码示例。如果您正苦于以下问题:Java MongoCollection.count方法的具体用法?Java MongoCollection.count怎么用?Java MongoCollection.count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.client.MongoCollection
的用法示例。
在下文中一共展示了MongoCollection.count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: successfulInputOfComment
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
@Test
public void successfulInputOfComment() throws IOException {
String json = "{ plantId: \"58d1c36efb0cac4e15afd278\", comment : \"Here is our comment for this test\" }";
assertTrue(plantController.storePlantComment(json, "second uploadId"));
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase(databaseName);
MongoCollection<Document> commentDocuments = db.getCollection("comments");
long contains = commentDocuments.count();
assertEquals(1, contains);
Iterator<Document> iter = commentDocuments.find().iterator();
Document fromDb = iter.next();
assertEquals("Here is our comment for this test", fromDb.getString("comment"));
assertEquals("16040.0", fromDb.get("commentOnPlant"));
assertEquals("second uploadId", fromDb.get("uploadId"));
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:22,代码来源:TestPlantComment.java
示例2: configure
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
private void configure() {
MongoDatabase db = this.mongoClient.getDatabase(dbName);
MongoCollection<Document> metadataColl = db.getCollection(METADATA_COLL_NAME);
if (metadataColl.count() > 1) {
throw new IndraError("Model metadata must have only one entry!");
}
if (metadataColl.count() == 1) {
logger.debug("Using stored metadata of {}", dbName);
Document storedMetadata = metadataColl.find().first();
metadata = ModelMetadata.createFromMap(storedMetadata);
}
else {
logger.debug("No metadata found in {}, using defaults.", dbName);
metadata = ModelMetadata.createDefault();
}
logger.info("Model metadata: {}", metadata);
}
示例3: countAction
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private List<Map> countAction(DataStoreMsg msg, Map queryparmes, MongoCollection<Document> collection) {
BasicDBObject query = new BasicDBObject();// output
Map findparmes = (Map) queryparmes.get(DataStoreProtocol.WHERE);
QueryStrategy qry = new QueryStrategy();
Map express = new LinkedHashMap();
express.put(DataStoreProtocol.FIND, findparmes);
qry.concretProcessor(DataStoreProtocol.FIND, express, query);
// for (Object qobj : query.keySet()) {
// log.info(this, "shell in package:" + qobj.toString() + ":" + query.get(qobj));
// }
log.info(this, "MongoDBDataStore countAction toJson : " + query.toJson());
long countN = collection.count(query);
Map<String, Object> item = new LinkedHashMap<String, Object>();
item.put(DataStoreProtocol.COUNT, countN);
List<Map> res = new ArrayList<Map>();
res.add(item);
return res;
}
示例4: count
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
/**
* 获取个数
*
* @param collectionName
* 表名
* @param filter
* 过滤
* @return
*/
public static long count(String collectionName, Bson filter) {
MongoCollection<Document> collection = getCollection(collectionName);
try {
if (filter == null) {
return collection.count();
} else {
return collection.count(filter);
}
} catch (Exception e) {
if (log != null) {
log.error("查询个数失败", e);
}
return 0;
}
}
示例5: getScanStats
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
@Override
public ScanStats getScanStats() {
try{
MongoClient client = storagePlugin.getClient();
MongoDatabase db = client.getDatabase(scanSpec.getDbName());
MongoCollection<Document> collection = db.getCollection(scanSpec
.getCollectionName());
String json = collection.find().first().toJson();
float approxDiskCost = json.getBytes().length * collection.count();
return new ScanStats(GroupScanProperty.EXACT_ROW_COUNT,
collection.count(), 1, approxDiskCost);
} catch (Exception e) {
throw new DrillRuntimeException(e.getMessage(), e);
}
}
示例6: count
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
/**
* Count the documents of a collection.
*
* @param collectionName name of the collection to insert the document in to.
* @return total no. of documents of a collection.
*/
public long count(final String collectionName) {
// Sanity checks
if (StringUtils.isEmpty(collectionName)) {
throw new IllegalArgumentException("count :: Collection name should not be blank");
}
// Collection
MongoCollection<Document> collection = this.database.getCollection(collectionName);
return collection.count();
}
示例7: id
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
@Then("^Lead with id (\\d+) should be in the database")
public void Lead_with_id_should_be_in_intellead_data_mongodb_database(int leadId) {
MongoDatabase database = mongoClientData.getDatabase("local");
MongoCollection<Document> collection = database.getCollection("leads");
long count = collection.count(parse("{_id: {$eq: \"" + leadId + "\"}}"));
assertEquals(1, count);
}
示例8: with
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
@Then("^Lead with ([\\w_\\.]+) equals to ([\\w ]+) should be in the database")
public void Lead_with_field_should_be_in_intellead_data_mongodb_database(String fieldName, String fieldValue) {
MongoDatabase database = mongoClientData.getDatabase("local");
MongoCollection<Document> collection = database.getCollection("leads");
long count = collection.count(parse("{\"" + fieldName + "\": {$eq: \"" + fieldValue + "\"}}"));
assertTrue(count >= 1);
}
示例9: failedInputOfComment
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
@Test
public void failedInputOfComment() throws IOException {
String json = "{ plantId: \"58d1c36efb0cac4e15afd27\", comment : \"Here is our comment for this test\" }";
assertFalse(plantController.storePlantComment(json, "second uploadId"));
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase(databaseName);
MongoCollection<Document> commentDocuments = db.getCollection("comments");
long contains = commentDocuments.count();
assertEquals(0, contains);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:14,代码来源:TestPlantComment.java
示例10: getLargestID
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
private int getLargestID() throws NotConnectedException {
try {
MongoCollection<Document> collection = getCollection();
if (collection.count() <= 0) {
return 0;
}
int largestID = (int) collection.find().sort(Sorts.descending("internalDbID")).limit(1).first().get("internalDbID");
return largestID;
} catch (Exception e) {
BackendprocessService.getInstance().logger.error("couldnt find largest id " + e.toString());
}
return 1;
}
示例11: executeCount
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
public JSONObject executeCount(String dbName, String collectionName, JSONObject reqJson) {
MongoDatabase db = mongoClient.getDatabase(dbName);
MongoCollection coll = db.getCollection(collectionName);
JSONObject resp = new JSONObject();
Document doc = Document.parse(reqJson.toString());
long count = coll.count(doc);
resp.put("Data", count);
return resp;
}
示例12: createBeds
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
private static void createBeds(String[][] plants) {
String[] keys = getKeys(plants);
int bedCol = 1;
for (int i = 0; i < keys.length; i++){
if (keys[i].equals("gardenLocation")){
bedCol = i;
break;
}
}
MongoClient mongoClient = new MongoClient();
MongoDatabase ddg = mongoClient.getDatabase("ddg");
MongoCollection beds = ddg.getCollection("beds");
beds.drop();
for (int i = 4; i < plants.length; i++){
String currentBed = plants[i][bedCol];
Bson filter = new Document("gardenLocation", currentBed);
if (beds.count(filter) == 0 && !currentBed.equals("")) {
Document doc = new Document("gardenLocation", currentBed);
beds.insertOne(doc);
}
}
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:29,代码来源:ExcelParser.java
示例13: getCount
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
public static int getCount(MongoCollection<Document> col) {
int count = (int) col.count();
return count;
}
示例14: count
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
public long count(MongoCollection<Document> collection) {
return collection.count();
}
示例15: successfulInputOfComment
import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
@Test
public void successfulInputOfComment() throws IOException {
String json = "{ plantId: \"16040.0\", comment : \"Here is our comment for this test\" }";
assertTrue(plantController.storePlantComment(json, "second uploadId"));
MongoCollection<Document> commentDocuments = testDB.getCollection("comments");
long contains = commentDocuments.count();
assertEquals(1, contains);
Iterator<Document> iter = commentDocuments.find().iterator();
Document fromDb = iter.next();
assertEquals("Here is our comment for this test", fromDb.getString("comment"));
assertEquals("16040.0", fromDb.get("commentOnPlant"));
assertEquals("second uploadId", fromDb.get("uploadId"));
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:20,代码来源:TestPlantComment.java