我有這種陣列與多個子陣列:mongodb的查詢子陣列
> 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"
},
]
}
我應該如何篩選子陣列(一個或多個)當前_id
的{"materias.id_materia" : '$in' ("4531",'4530'),'parcial3':10}
?
任何幫助php db->find
或JavaScript將有所幫助。
謝謝你所有的答案,最後一個做到了這個訣竅,雖然mongo <2.2中的$ elemMatch並不能很好地工作。我需要升級到2.4.5版本 –