I am working with ASP.net Core, MongoDB.Driver 2.13.0, and a MongoDB document with the following structure:
"lrec80" : [
{
"RR4NFAD" : {
"$ref" : "RR4OCO",
"$id" : ObjectId("00000000000000008c8a414b"),
"$db" : "tpfdf"
},
"RR4NRCC" : 43,
"RR4NAKY" : 0,
"RR4NA80" : {
"RR4NSDT" : { "$binary" : "UOE=", "$type" : "00" }
},
"RR4NPDT" : { "$binary" : "UOs=", "$type" : "00" },
"RR4NTY1" : -124,
"RR4NCTY" : "IAH",
"RR4NLIA" : null,
"RR4NNBR" : 1
},
My POCO objects maps almost all the fields I need, with the exception of the "RR4NFAD" object.
public class RR4NFAD
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public ObjectId Id { get; set; }
[BsonElement("$ref")]
public string Ref { get; set; }
[BsonElement("$db")]
public string DB { get; set; }
}
If I set Id property to ObjectId type, I get the DB and Ref fields successfully, but Id field shows the following:
Id = {000000000000000000000000}
CreationTime = 1/1/1970 12:00:00 AM
Increment = 0
Machine = 0
Pid = 0
Timestamp = 0
If I set Id field to string:
public class RR4NFAD
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonElement("$ref")]
public string Ref { get; set; }
[BsonElement("$db")]
public string DB { get; set; }
}
Id returns as null, but I still get the DB and Ref fields successfully
I've tried creating a ObjectIdConverter without success and applying it as an attribute on the Id field using the following example:
Returning ObjectID as a string from ASP.NET Core
How can I get the RR4NFAD Id field to return as one of the following as a reference to query another document?
- ObjectId("00000000000000008c8a414b")
- "00000000000000008c8a414b"
Thanks for any help you can offer. Seems like a simple problem, but I'm new to MongoDB and it's giving me fits.
