0
MongoCollection<Document> Person_List = db.getCollection("Person");
MongoCollection<Document> active_list = db.getCollection("activelist"); 
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD"); 
String todaydate = format.format(new Date()); 
ArrayList<Document> 
activeList=Person_List.find(Filters.regex("LastUpdate",todayDate.toString())).into(new 
ArrayList<Document>());

This is the code what we have written, here we need to fetch the month from todaydate and need to compare with month of LastUpdate field, how to fetch the month from LastUpdate document field in mongo db, LastUpdate is the date string, can someone please help me.

Slava Semushin
  • 14,904
  • 7
  • 53
  • 69
  • @Slava Semushin can u help me please – Prasad Mayya M Jun 09 '20 at 13:24
  • I don't use Mongo, but perhaps these questions could help you: https://stackoverflow.com/questions/18907566/mongodb-query-specific-monthyear-not-date or this one https://stackoverflow.com/questions/6840540/java-mongodb-query-by-date It seems like $month (https://docs.mongodb.com/manual/reference/operator/aggregation/month/#exp._S_month) is what you're looking for. HTH – Slava Semushin Jun 09 '20 at 15:58

0 Answers0