0

I have a mongo collection as shown below

{
    "_id" : ObjectId("5c5c86633b897535539c1b36"),
    "studentId" : "dsdlkjafhiuelfdldahfiu",
    "marks" : [
        "subject" : "Physics",
        "sectionMap" : {
            "section_1" : {
                "scale" : 0,
                "unscaled" : NumberLong(1)
            },
            "section_2" : {
                "scale" : 0,
                "unscaled" : NumberLong(10)
            }
        },
        "detailMap" : {
            "Mechanics" : {
                "scale" : 0,
                "unscaled" : NumberLong(3)
            },
            "Optics" : {
                "scale" : 0,
                "unscaled" : NumberLong(3)
            },
            "Fluid Mechanics" : {
                "scale" : 0,
                "unscaled" : NumberLong(5)
            }
        }, 
        ...
    ]
}

From the above collection, I want to fetch all the records for which the sum of sectionMap and sum of detailMap is not the same. The number of entries in sectionMap and detailMap can change.

From all the examples that I looked up online all of them had fixed attribute names. Is there a way to group sectionMap and detailMap and compare them in the same query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.