我不知道,如果冠軍爭奪戰中我所期待的,但在這裏它是: 我有一個JSON看起來像這樣:MongoDB中查詢到POCO項目單一陣列項目
[
{
"Class" : "Math",
"Location" : "South Hall",
"Professor" : "Donald Duck"
"Student":
[
{
"FirstName" : "John",
"LastName" : "Doh",
"DOB" : "1990",
"SS": "123456789"
},
{
"FirstName" : "Jane",
"LastName" : "Smith",
"DOB" : "1990",
"SS": "023456789"
},
{
"FirstName" : "John",
"LastName" : "Smith",
"DOB" : "1995",
"SS": "003456789"
}
]
}
]
我希望能夠使用學生名字和姓氏閱讀文檔,但是我只想返回此學生的數組項目以及其餘的json,並排除其餘學生,例如,說我的查詢是:
db.Class.find({"Student.FirstName" : "Jane", "Student.LastName" : Smith"})
我希望我的返回JSON看起來像這樣:
[
{
"Class" : "Math",
"Location" : "South Hall",
"Professor" : "Donald Duck"
"Student":
{
"FirstName" : "Jane",
"LastName" : "Smith",
"DOB" : "1990",
"SS": "023456789"
}
}
]
任何想法如何做到這一點?我現在用的是C#司機和我的POCO是這樣的:
public class Rootobject
{
public string Class { get; set; }
public string Location { get; set; }
public string Professor { get; set; }
public Student Student { get; set; }
}
public class Student
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string DOB { get; set; }
public string SS { get; set; }
}
@Pacman如果答案對你有幫助,我會感激不盡。 –