0

I need to find the record/count where eventDetails.eventDelivery.stateCode = "Y-FINISH". It could be in any element in the array list.

Just want to find where stateCode = "Y-FINISH" present in the array list.

Sample Data #1:
{
    "_id" : ObjectId("5a2fb09736cf07f6a1146691"),
    "activityID" : "",
    "eventDetails" : [ 
        {
            "eventDelivery" : {
            "digital" : {
                "secureid" : "1231321212"
            },
            "stateCode" : "X-FINISH",
            "state" : "SUCCESS"
        }, 
        {
            "eventDelivery" : {
            "digital" : {
                "secureid" : "8762871121"
            },
            "stateCode" : "Y-FINISH",
            "state" : "SUCCESS"            
        }
    ],
}

Sample Data #2:
    {
        "_id" : ObjectId("5a2fb09736cf07f6a1146691"),
        "activityID" : "",
        "eventDetails" : [ 
            {
                "eventDelivery" : {
                "digital" : {
                    "secureid" : "1231321212"
                },
                "stateCode" : "X-FINISH",
                "state" : "SUCCESS"
            }, 
            {
                "eventDelivery" : {
                "digital" : {
                    "secureid" : "8762871121"
                },
                "stateCode" : "Y-FINISH",
                "state" : "SUCCESS"            
            }, 
            {
                "eventDelivery" : {
                "digital" : {
                    "secureid" : "7651327152
                },
                "stateCode" : "Z-FINISH",
                "state" : "SUCCESS"            
            }
        ],
    }

Need to read this using Java.

1 Answer 1

1

Using a 3.x version of the Mongo Java driver ...

MongoClient mongoClient = ...;

MongoCollection<Document> collection = mongoClient.getDatabase("...")
    .getCollection("...");

Bson filter = Filters.eq("eventDetails.stateCode", "Y-FINISH");

long count = collection.count(filter);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.