2
我有數據看起來像下面如何元素MongoDB中.NET司機推到陣列中
> db.people.findOne({"Name":"Jones"})
{
"_id" : ObjectId("551dcbdc360fbd77107f8a37"),
"Name" : "Jones",
"Age" : 30,
"Profession" : "Hacker"
}
的類定義爲
class Person
{
public ObjectId Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public List<string> Colors { get; set; }
public List<Pet> Pets { get; set; }
}
class Pet
{
public string Name { get; set; }
public string Type { get; set; }
}
我嘗試寵物元素推到寵物字段
var pet = new Pet
{
Name = "Boneless",
Type = "Gold Fish",
};
var result = await coll_t.UpdateOneAsync(Builders<Person>.Filter.Eq("Name", "Jones"), Builders<Person>.Update.Push(x => x.Pets, pet));
Console.WriteLine(string.Format("MatchedCount = {0}; ModifiedCount = {1}; UpsertedId = '{2}';"), result.MatchedCount.ToString(), result.ModifiedCount.ToString(), result.UpsertedId.ToString());
更新沒有錯誤。但它沒有更新。結果中的MatchedCount是0,ModifiedCount也是0.我錯過了什麼?
謝謝,
PS。 Console.WriteLine(....)不會顯示任何它看起來像遇到未捕獲錯誤的任何內容。任何想法?