1

I have this array with multiple sub-arrays:

> db.alumnos111.findOne({curp:'AELJ951211MASCPN04'})
{
        "_id" : ObjectId("520d5440bee9577c283542c3"),
        "nocontrol" : "10301051680201",
        "nombre" : "JANETTE ARACELI",
        "paterno" : "ACERO",
        "materno" : "LOPEZ",
        "curp" : "AELJ951211MASCPN04",
        "generacion" : "2010-2013",
        "carrera" : "INFORMÁTICA",
        "clv_centro" : "01DCT0001F",
        "estado" : "AGUASCALIENTES",
        "plantel" : "CBTIS NO. 168",
        "id_plantel" : "513",
        "materias" : [
                {
                        "semestre" : "4",
                        "nombre_asignatra" : "ECOLOGÍA",
                        "grupo" : "4A",
                        "turno1" : "2001",
                        "parcial1" : "10",
                        "parcial2" : "9",
                        "parcial3" : "9",
                        "calificacion" : "9",
                        "periodo" : "SEMESTRAL 2 - 2011",
                        "id_periodo" : "111",
                        "id_plangpo" : "14",
                        "id_materia" : "4529"
                },
                {
                        "semestre" : "4",
                        "nombre_asignatra" : "FÍSICA I",
                        "grupo" : "4A",
                        "turno1" : "2001",
                        "parcial1" : "8",
                        "parcial2" : "10",
                        "parcial3" : "10",
                        "calificacion" : "9",
                        "periodo" : "SEMESTRAL 2 - 2011",
                        "id_periodo" : "111",
                        "id_plangpo" : "14",
                        "id_materia" : "4530"
                },          
                {
                        "semestre" : "4",
                        "nombre_asignatra" : "INGLÉS IV",
                        "grupo" : "4A",
                        "turno1" : "2001",
                        "parcial1" : "8",
                        "parcial2" : "10",
                        "parcial3" : "9",
                        "calificacion" : "9",
                        "periodo" : "SEMESTRAL 2 - 2011",
                        "id_periodo" : "111",
                        "id_plangpo" : "14",
                        "id_materia" : "4531"
                },        

        ]
}

How should I filter the subarray(s) {"materias.id_materia" : '$in' ("4531",'4530'),'parcial3':10} of the current _id?

Any help in php db->find or JavaScript would be helpful.

2 Answers 2

2

Your query should looks something like this

db.alumnos111.find({"materias.id_materia" : { $in : [ "1234", "5678"] }})

to filter out documents w/ id_materia="1234" OR id_materia="5678"

This example would be javascript executed straight in the mongo shell

Sign up to request clarification or add additional context in comments.

Comments

2

You can also try this:

db.alumnos111.find( { _id: id }, { materias: { $elemMatch: { id_materia: $in: [ "4531","4530" ], parcial3: 10} }

1 Comment

Thank you for all the answers, the last one did the trick, although the $elemMatch in mongo < 2.2 does not work at all good. I needed to upgrade to 2.4.5 version

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.