|
Here's a workaround you can use until this ticket is implemented:
var connectionString = "mongodb://localhost/?safe=true";
|
var server = MongoServer.Create(connectionString);
|
var database = server.GetDatabase("test");
|
var collection = database.GetCollection("test");
|
|
var id = ObjectId.GenerateNewId();
|
var document = new BsonDocument
|
{
|
{ "_id", id },
|
{ "zipcode", 63109 },
|
{ "dependents", new BsonArray {
|
new BsonDocument { { "name", "john" }, { "school", 102 }, { "age", 10 } },
|
new BsonDocument { { "name", "jess" }, { "school", 102 }, { "age", 11 } },
|
new BsonDocument { { "name", "jeff" }, { "school", 108 }, { "age", 15 } }
|
}}
|
};
|
if (collection.Exists()) { collection.Drop(); }
|
collection.Insert(document);
|
|
var query = Query.EQ("zipcode", 63109);
|
var fields = new FieldsDocument
|
{
|
{ "_id", 0 },
|
{ "dependents", new BsonDocument("$elemMatch", new BsonDocument("school", 102)) }
|
};
|
foreach (var partialDocument in collection.Find(query).SetFields(fields))
|
{
|
Console.WriteLine(partialDocument.ToJson());
|
}
|
|