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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.