It was about updating the country collection, and not inserting. Guess there are two ways to work with MongoDB, one being through a context using the driver, and the other working with the MongoDB .Net Core driver straight. This is where I got confused. So I'm using my MongoDBContext in my repositories which are CRUD and just the driver in my services which are REST. Anyways, this is just a learning exercise for later use. I'll dump it and replace it with a text file written in the same BSON format later down the road. But at least I got this working for now, well I haven't consumed yet so I'll find out.
// Let See if we can inject the States collection into Countries/States
var filter_US = Builders.Filter.Eq(s => s.ShortName, country.ShortName.ToUpper());
var update_US = Builders.Update.Set(s => s.States, states_US);
await websiteCountries.UpdateOneAsync(filter_US, update_US);
And my result, I saw Arizona is wrong, fixed.
{
"_id" : ObjectId("5b8434defb1e6524f8cc0554"),
"DisplayId" : "5b8434defb1e6524f8cc0554",
"LongName" : "United States",
"ShortName" : "US",
"States" : [
{
"_id" : ObjectId("5b8434dffb1e6524f8cc0582"),
"Name" : "Alabama",
"Abbr" : "AL"
},
{
"_id" : ObjectId("5b8434dffb1e6524f8cc0583"),
"Name" : "Alaska",
"Abbr" : "AK"
},
{
"_id" : ObjectId("5b8434dffb1e6524f8cc0583"),
"Name" : "Arizona",
"Abbr" : "AZ"
},
{
"_id" : ObjectId("5b8434dffb1e6524f8cc0585"),
"Name" : "Arkansas",
"Abbr" : "AR"
},
On a side not about my Angular V6 .Net Core 2.1 training exercise: I finally got all my folders and files organized efficiently. Basically modules, components and services in Angular, plus my routing with lazy loading is correct. Figured out how to change navbars and footers using *ngIf. Got my new Auth Guard authentication working in Angular, including the Auth0 token and wrote a REST service in .Net Core to handle it, with cookies and token generation. My ContactUs works with my CRUD Repository, just have to write the email part, and figure out if I should do it in .Net Core, Angular or write something in NodeJS for it. Perhaps a .Net console app. So now I can move forward with more head scratchers and frustration. What I have learned so far is that Angular V6 is one th