package com.leo.test;
import au.com.bytecode.opencsv.CSVReader;
import com.mongodb.*;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import org.bson.types.Binary;
import org.bson.types.ObjectId;
import java.io.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author leo
* @date 2022/4/6 14:52
*/
public class LeoFileDownTest {
public static void main(String[] args) throws IOException {
ServerAddress serverAddress = new ServerAddress("127.0.0.1", 47117);
List<ServerAddress> addrs = new ArrayList<>();
addrs.add(serverAddress);
MongoCredential credential = MongoCredential.createCredential("tfsadmin", "TFS", "123456".toCharArray());
MongoClientOptions.Builder builder = MongoClientOptions.builder();
MongoClientOptions clientOptions = builder.build();
MongoClient mongoClient = new MongoClient(addrs, credential, clientOptions);
MongoDatabase tfs = mongoClient.getDatabase("TFS");
MongoCollection<Document> collection = tfs.getCollection("fs.files");
BasicDBObject query2 = new BasicDBObject();
query2.append("metadata._fileDataType_", 1);
query2.append("metadata._fileIsAnalysis_", 1);
query2.put("metadata.afterDate", new BasicDBObject("$gte", "20220328000000"));
// 查询该条件下数据的数量
long count = collection.count(query2);
System.out.println("count ---> " + count);
// 更新数据
BasicDBObject set = new BasicDBObject();
set.append("$set", new BasicDBObject("metadata._fileIsAnalysis_", 0));
collection.updateMany(query2, set);
}
}
|