php - mongodb querying sub array -
i have array 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 filter subarray(s) {"materias.id_materia" : '$in' ("4531",'4530'),'parcial3':10}
of current _id
?
any in php db->find
or javascript helpful.
your query should looks this
db.alumnos111.find({"materias.id_materia" : { $in : [ "1234", "5678"] }})
to filter out documents w/ id_materia="1234" or id_materia="5678"
this example javascript executed straight in mongo shell
Comments
Post a Comment