I have a MongoDB collection which contains 6 fields in single document, for example:
{
"_id" : ObjectId("59d0f2382043f72a443e6ec0"),
"TranDate" : "2017-07-25T18:01:12+08:00",
"TranCode" : "ActFLA_A01_01_",
"TranValue" : "812.34",
"Seq" : "71",
"Configuration" : "10"
},
{
"_id" : ObjectId("59d0f2332043f72a443e1397"),
"TranDate" : "2017-07-25T18:01:12+08:00",
"TranCode" : "ActFLA_A01_01_",
"TranValue" : "87.34",
"Seq" : "71",
"Configuration" : "10"
},
{
"_id" : ObjectId("59d0f2332043f72a443e1397"),
"TranDate" : "2017-07-25T18:01:12+08:00",
"TranCode" : "ActFLA_A01_01_",
"TranValue" : "828.34",
"Seq" : "71",
"Configuration" : "10"
},
{
"_id" : ObjectId("59d0f2342043f72a443e16be"),
"TranDate" : "2017-07-25T00:45:02+08:00",
"TranCode" : "ActFLA_A01_01_",
"TranValue" : "0.00",
"Seq" : "2",
"Configuration" : "0"
}
Here is my code for query:
Pattern regex = Pattern.compile("^2017-07-25");
Pattern regex2 = Pattern.compile("^ActFLA_A");
Pattern regex3 = Pattern.compile("^10");
DBObject clause1 = new BasicDBObject("TranDate", regex);
DBObject clause2 = new BasicDBObject("TranCode", regex2);
DBObject clause3 = new BasicDBObject("Configuration", regex3);
BasicDBList and = new BasicDBList();
and.add(clause1);
and.add(clause2);
and.add(clause3);
DBObject query = new BasicDBObject("$and", and);
I am getting only one Document but I am expecting 3 Documents which contain (Fields) TranDate, TranCode, TranSeq and Configuration with same value except TranValue.
BasicDBList and. And you should add the code you use for retrieving the matches. May be the problem is there.