I'm working my way through a Plural Sight course to get some insight in MongoDB. It's one of the basic courses on the 'path' and it seems to have been made pre 2.0. As such I'm having some trouble understanding some of the subjects the tutor is going through.
I was hoping to see if someone could clarify how to Find
any object based on their BsonID
?
This is my object:
public class Patient
{
[BsonElement("_id")]
[BsonId]
public string Name { get; set; }
public ICollection<Ailment> Ailments { get; set; }
public ICollection<Medication> Medications { get; set; }
}
And this is how I'm trying to query it:
public HttpResponseMessage Get(int id)
{
var patient = _patients.Find(pat => pat._id == id).ToList();
if(patient == null)
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Patient Not Found..");
}
return Request.CreateResponse(HttpStatusCode.OK, patient);
}
This syntax doesn't allow me to build the project as there isn't a property with the name _id
. I've also attempted to have an actual property ID, but that seems to create some sort of a problem when building (most likely since I already have an ID in it, created by BsonID).
I'm really sorry if this question has been asked before, but I seriously couldn't find any help on the subject. It seems like there should be a lot of resources on it (ie. us newbies should be able to get some good sources back when searching for something like "c# querying mongodb find on BsonId").
I fully understand if this is going to be down voted, but I'd really love it if someone with some time over could help me out here.