Q:

3 conditions with and does not work

I am new to mongodb:
I have a db contains some documents as follow:
/* 2 */
{
    "_id" : ObjectId("546ea531d38ed4b9eaaa46eb"),
    "name" : "hamed",
"time" : "20141105220011",
    "entity" : [ 
        "10", 
        "11"
    ]
}

/* 3 */
{
    "_id" : ObjectId("546ecb07badc664b0b18ba95"),
    "name" : "ali",
    "time" : "20141105230011",
    "entity" : [ 
        "12", 
        "13"
    ]
}

Now I am trying to return all docs that contains (entity between 11 or 12 ) and "20141105230011"

for that I use the following code:
MongoClient mongoClient = new MongoClient("localhost", 27017);
    DB db = mongoClient.getDB("test");
    DBCollection coll = db.getCollection("test");
    BasicDBObject oredrFields = new BasicDBObject();
    DBObject inOp = new BasicDBObject();
    BasicDBObject filtercol = new BasicDBObject();
    inOp.put("$in", new String[] { "10", "1" });
    filtercol.put("_id", 0);
    filtercol.put("name", 1);
    filtercol.put("entity", 1);
    filtercol.put("time", 1);
    oredrFields.put("entity", inOp);
    BasicDBObject andQuery = new BasicDBObject();
    BasicDBObject timeQuery = new BasicDBObject();
    timeQuery.put("time", new BasicDBObject("$gt","20131105241311"));
    List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
    obj.add(timeQuery);
    obj.add(oredrFields);
    obj.add(filtercol);
    andQuery.put("$and", obj);
    DBCursor cursor = coll.find(andQuery);
    try {
        while (cursor.hasNext()) {
            System.out.println(cursor.next());
        }
    } finally {
        cursor.close();
    }

But when I run it nothing returns though I have some data in the database that meet the conditions!!!!
Can anyone help? (I am totally confused)

A:

You have complicated the query with unnecessary DBObjects. The below code represents how to build the DBObject with a condition to match the documents with entity in 11 or 12, and time = 20141105230011.
    MongoClient mongoClient = new MongoClient("localhost", 27017);
    DB db = mongoClient.getDB("test");
    DBCollection coll = db.getCollection("test");

    DBObject inOp = new BasicDBObject();
    inOp.put("$in", new String[] { "11", "12" });

    BasicDBObject query = new BasicDBObject();
    query.put("entity", inOp);
    query.put("time", "20141105230011");

    BasicDBObject filter = new BasicDBObject().append("_id", 0).
    append("entity", 1).append("time", 1).append("name",1);

    DBCursor cursor = coll.find(query,filter);
    try {
        while (cursor.hasNext()) {
            System.out.println(cursor.next());
        }
    } finally {
        cursor.close();
    }

