本文整理匯總了Java中com.mongodb.client.MongoCollection.deleteMany方法的典型用法代碼示例。如果您正苦於以下問題:Java MongoCollection.deleteMany方法的具體用法?Java MongoCollection.deleteMany怎麽用?Java MongoCollection.deleteMany使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mongodb.client.MongoCollection
的用法示例。
在下文中一共展示了MongoCollection.deleteMany方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deleteManyDocument
import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
/**
* This is deleted delete all document(s), which is matched
*/
@Override
public void deleteManyDocument() {
MongoDatabase db = null;
MongoCollection collection = null;
Bson query = null;
try {
db = client.getDatabase(mongo.getDataBase());
collection = db.getCollection(mongo.getSampleCollection());
query = lt("age", 20);
DeleteResult result = collection.deleteMany(query);
if (result.wasAcknowledged()) {
log.info("Document deleted successfully \nNo of Document(s) Deleted : "
+ result.getDeletedCount());
}
} catch (MongoException e) {
log.error("Exception occurred while delete Many Document : " + e, e);
}
}
示例2: deleteOneDocument
import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
/**
* This is delete the single document, which is first matched
*/
@Override
public void deleteOneDocument() {
MongoDatabase db = null;
MongoCollection collection = null;
Bson query = null;
try {
db = client.getDatabase(mongo.getDataBase());
collection = db.getCollection(mongo.getSampleCollection());
query = eq("name", "sundar");
DeleteResult result = collection.deleteMany(query);
if (result.wasAcknowledged()) {
log.info("Single Document deleted successfully \nNo of Document Deleted : " + result.getDeletedCount());
}
} catch (MongoException e) {
log.error("Exception occurred while delete Single Document : " + e, e);
}
}
示例3: setLiveUploadId
import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
public static void setLiveUploadId(String uploadID){
MongoClient mongoClient = new MongoClient();
MongoDatabase test = mongoClient.getDatabase("test");
MongoCollection configCollection = test.getCollection("config");
configCollection.deleteMany(exists("liveUploadId"));
configCollection.insertOne(new Document().append("liveUploadId", uploadID));
}
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-3-sixguysburgers-fries,代碼行數:10,代碼來源:ExcelParser.java
示例4: setLiveUploadID
import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
public void setLiveUploadID(String uploadID){
MongoClient mongoClient = new MongoClient();
MongoDatabase test = mongoClient.getDatabase(databaseName);
MongoCollection configCollection = test.getCollection("config");
configCollection.deleteMany(exists("liveUploadID"));
configCollection.insertOne(new Document().append("liveUploadID", uploadID));
}
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-4-dorfner-v2,代碼行數:10,代碼來源:ExcelParser.java
示例5: main
import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
// 連接到 mongodb 服務
MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
// 連接到數據庫
MongoDatabase mongoDatabase = mongoClient.getDatabase("mycol");
System.out.println("Connect to database successfully");
MongoCollection<Document> collection = mongoDatabase.getCollection("test");
System.out.println("集合 test 選擇成功");
// //插入文檔
// /**
// * 1. 創建文檔 org.bson.Document 參數為key-value的格式
// * 2. 創建文檔集合List<Document>
// * 3. 將文檔集合插入數據庫集合中 mongoCollection.insertMany(List<Document>) 插入單個文檔可以用 mongoCollection.insertOne(Document)
// * */
// Document document = new Document("title", "MongoDB").
// append("description", "database").
// append("likes", 100).
// append("by", "Fly");
// List<Document> documents = new ArrayList<Document>();
// documents.add(document);
// collection.insertMany(documents);
// System.out.println("文檔插入成功");
// //檢索所有文檔
// /**
// * 1. 獲取迭代器FindIterable<Document>
// * 2. 獲取遊標MongoCursor<Document>
// * 3. 通過遊標遍曆檢索出的文檔集合
// * */
// FindIterable<Document> findIterable = collection.find();
// MongoCursor<Document> mongoCursor = findIterable.iterator();
// while(mongoCursor.hasNext()){
// System.out.println(mongoCursor.next());
// }
// //更新文檔 將文檔中likes=100的文檔修改為likes=200
// collection.updateMany(Filters.eq("likes", 100), new Document("$set",new Document("likes",200)));
// //檢索查看結果
// FindIterable<Document> findIterable = collection.find();
// MongoCursor<Document> mongoCursor = findIterable.iterator();
// while(mongoCursor.hasNext()){
// System.out.println(mongoCursor.next());
// }
//刪除符合條件的第一個文檔
collection.deleteOne(Filters.eq("likes", 200));
//刪除所有符合條件的文檔
collection.deleteMany (Filters.eq("likes", 200));
//檢索查看結果
FindIterable<Document> findIterable = collection.find();
MongoCursor<Document> mongoCursor = findIterable.iterator();
while(mongoCursor.hasNext()){
System.out.println(mongoCursor.next());
}
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
}
}
示例6: delete
import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
/**
* 按條件刪除
*
* @param collectionName 集合名
* @param query 查詢條件
* @return
*/
public boolean delete(String collectionName, MongodbQuery query) {
MongoCollection collection = sMongoDatabase.getCollection(collectionName);
DeleteResult deleteResult = collection.deleteMany(query.getQuery());
return deleteResult.getDeletedCount() > 0;
}