1

I've been working with mongo for a few months and I'm struggling now.

Here is a document example of my database:

"_id" : ObjectId("5732d96fed40761e640a3f3e"),
"_familyId" : "12345",
"_applications" : [
{
    "_applicationRID" : "123456",
    "_applicationDate" : "01012000",
    "_isRepresentative" : false,
    "_applicationId" : {
            "CC" : "AB",
            "SN" : "123456789",
            "KC" : "A"
    },
    "_publications" : [
    {
        "_publicationRID" : "123456789",
        "_publicationDate" : "01012000",
        "_flaId" : "AB123456789A",
        "_publicationId" : {
                "CC" : "AB",
                "SN" : "1234567",
                "KC" : "B"
        }, 

[...] 

Now, I'm trying to do a collection.find() in Java on an array. I know all the fields contained in _publicationId and I need to search on _publicationId because it has an index but not the fields inside it.

In shell it would be:

db.collection.find({
    "_applications._publications._publicationId": {
        "CC": "AB",
        "SN": "1234567",
        "KC": "B"
    }
})

and this works fine.

Using java, I can't find the proper syntax:

collection.find("_applications._publications._publicationId",  ??? )
4

1 回答 1

0

您应该尝试下一个类型的查询,该查询实际上与您在 java 中的查询完全等效:

DBObject query = new BasicDBObject(
    "_applications._publications._publicationId",
    new BasicDBObject("CC", "AB").append("SN", "1234567").append("KC", "B")
);
DBCursor cursor = collection.find(query);
于 2016-10-27T10:51:18.757 回答