Unfortunately, I cannot find an example for Mongo 3.2 java driver for query like "(A or B or C) and (D or E or F or G)" 

Number of parameters inside parentheses will be variable - **up to hundred**.

Funny thing that I've found example for "(A && B) || (X && Y)" but it doesn't help me.

[How to execute queries with both AND and OR clauses in MongoDB with Java](https://stackoverflow.com/questions/36753254/how-to-execute-queries-with-both-and-and-or-clauses-in-mongodb-with-java)

My code produces error:

**MongoQueryException: Query failed with error code 2 and error message '$or/$and/$nor entries need to be full objects'**

```
List<Document> docs = new ArrayList<>();

for (Integer ln: input.getLastnames()) {
        docs.add(new Document("lastname",ln));
    }

    Document queryLN = new Document(
            "$or", Arrays.asList(docs)
    );

    docs.clear();
    for (Integer fn: input.getFirstnames()) {
        docs.add(new Document("firstname",fn));
    }

    Document queryFN = new Document(
            "$or", Arrays.asList(docs)
    );

    Document query = new Document(
            "$and", Arrays.asList(queryFN,queryLN));

    List<Document> result = collectionMain.find(query).into(new ArrayList<Document>());

```