【发布时间】:2011-06-07 14:43:04
【问题描述】:
我正在使用 10Gen 认可的 c# 驱动程序,用于 mongoDB 的 c# 应用程序和数据浏览,我正在使用 Mongovue。
以下是两个示例文档架构:
{
"_id": {
"$oid": "4ded270ab29e220de8935c7b"
},
"Relationships": [
{
"RelationshipType": "Person",
"Attributes": {
"FirstName": "Travis",
"LastName": "Stafford"
}
},
{
"RelationshipType": "Student",
"Attributes": {
"GradMonth": "",
"GradYear": "",
"Institution": "Test1",
}
},
{
"RelationshipType": "Staff",
"Attributes": {
"Department": "LIS",
"OfficeNumber": "12",
"Institution": "Test2",
}
}
]
},
{
"_id": {
"$oid": "747ecc1dc1a79abf6f37fe8a"
},
"Relationships": [
{
"RelationshipType": "Person",
"Attributes": {
"FirstName": "John",
"LastName": "Doe"
}
},
{
"RelationshipType": "Staff",
"Attributes": {
"Department": "Dining",
"OfficeNumber": "1",
"Institution": "Test2",
}
}
]
}
我需要一个查询来确保满足两个 $elemMatch 条件,以便我可以匹配第一个文档,但不能匹配第二个文档。以下查询在 Mongovue 中有效。
{
'Relationships': { $all: [
{$elemMatch: {'RelationshipType':'Student', 'Attributes.Institution': 'Test1'}},
{$elemMatch: {'RelationshipType':'Staff', 'Attributes.Institution': 'Test2'}}
]}
}
如何在我的 c# 代码中执行相同的查询?
【问题讨论】:
标签: c# mongodb mongodb-.net-driver