本文整理汇总了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;
}