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


Java MongoCollection.count方法代碼示例

本文整理匯總了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);
}
 
開發者ID:Lambda-3,項目名稱:Indra,代碼行數:21,代碼來源:MongoVectorSpace.java

示例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;

}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:27,代碼來源:MongoDBDataStore.java

示例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;
	}

}
 
開發者ID:dianbaer,項目名稱:grain,代碼行數:26,代碼來源:MongodbManager.java

示例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);
  }
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:16,代碼來源:MongoGroupScan.java

示例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();
}
 
開發者ID:millij,項目名稱:osm-processor,代碼行數:17,代碼來源:MongoStore.java

示例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);
}
 
開發者ID:intellead,項目名稱:intellead-integration-tests,代碼行數:8,代碼來源:Steps.java

示例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);
}
 
開發者ID:intellead,項目名稱:intellead-integration-tests,代碼行數:8,代碼來源:Steps.java

示例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;
}
 
開發者ID:Saphs,項目名稱:Mp3Bib,代碼行數:14,代碼來源:Database.java

示例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;
    }
 
開發者ID:breakEval13,項目名稱:rocketmq-flink-plugin,代碼行數:12,代碼來源:MongoManager.java

示例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;
}
 
開發者ID:jiumao-org,項目名稱:wechat-mall,代碼行數:5,代碼來源:MongoCRUD.java

示例14: count

import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
public long count(MongoCollection<Document> collection) {
    return collection.count();
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:4,代碼來源:DatabaseConnection.java

示例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


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