1. 程式人生 > >mongo 批量刪除符合條件的資料(java程式碼)

mongo 批量刪除符合條件的資料(java程式碼)

//七天前的資料

Bson createTimeBson = Filters.lte("creatTime",  DateTimeUtils.addSomeDay(new Date(), -7));

//in 條件

Bson parentPushTypeBson = Filters.in("parentPushType", "03","04");

//用and連結

Bson bson = Filters.and(createTimeBson, parentPushTypeBson);

//批量刪除

MongoUtil.getCollection("userMessage").deleteMany(

bson);