I don't know if its just me but I've found the documentation for the mongodb c# driver to be so limited. Every time I try to do something more than a basic get/insert I end up in trial and error mode...
So I have a json document looks roughly something like ...
{
Year: "2015",
Vehicles : [
VehicleType : "Trucks",
Makes: [
{
Name: "Ford",
Models:
[
{
Name: "F150",
Sales:
[
{
Ref: FORDTRUCK01,
Month: 01,
Sold: 100,
Total: $10,000
},
{
Ref: FORDTRUCK02
Month: 02,
Sold: 150,
Total: $12,000
}
]
},
{
Name: "F350",
Sales:
[
{
Ref: FORDTRUCK03,
Month: 01,
Sold: 100,
Total: $10,000
},
{
Ref: FORDTRUCK04
Month: 02,
Sold: 150,
Total: $12,000
}
]
}
]
}
]
]
},
{
Year: "2014",
Vehicles : [
VehicleType : "Trucks",
Makes: [
{
Name: "Ford",
Models:
[
{
Name: "F250",
Sales:
[
{
Ref: FORDTRUCK01,
Month: 01,
Sold: 100,
Total: $10,000
},
{
Ref: FORDTRUCK02
Month: 02,
Sold: 150,
Total: $12,000
}
},
{
Name: "F150",
Sales:
[
{
Ref: FORDTRUCK03,
Month: 01,
Sold: 100,
Total: $10,000
},
{
Ref: FORDTRUCK04
Month: 02,
Sold: 150,
Total: $12,000
}
}
]
]
}
]
]
}
All I want to do is delete the embedded sales document for
Ref: FORDTRUCK01 where Year is 2015
without having to pass the entire document back and forth - this is a contrived example of what is actually a much larger document I don't see the need to either re-get the whole document ... or edit the document on the client and pass the entire thing back when all I want to do is delete 4 fields (one embedded document) based on these two parameters. so this is my hodgepodge of code from other SO posts I found - Im fairly certain my issue is with the first parameter of the PullFilter - but I can't seem to find an example that is deeper than one level of the bsondocument
var client = new MongoClient(connection);
var db = client.GetDatabase("db");
var collection = db.GetCollection<BsonDocument>("Vehicles");
BsonDocument filter = new BsonDocument("Year", year);
BsonDocument update = Builders<SalesYear>.Update.PullFilter("Vehicles.Makes.Models.Sales", Builders<SalesMonth>.Filter.Eq("Ref", "FORDTRUCK01")).ToBsonDocument();
var result = collection.FindOneAndUpdateAsync(filter, update).Result;
I keep getting an exception
{"Element name '_t' is not valid'."}
Any help greatly appreciated. If anyone could point me to good .net resources for the c# 2.0 driver would also be greatly appreciated