In .net there is the notion of mappings with the mongodb driver so you can keep your class db agnostic and just set a mapping class to decide how to convert your actual class through to the mongo one. So for example if I had:
public class MyEntity
{
public Guid Id {get;set;}
public string Name {get;set;}
}
I could tell it to use my Id field for the ObjectId when it turns it to BSON, keeping everything nice and separated. Currently I am looking at implementing something similar in Nodejs as I have some classes which are similar (I say classes but lets not get onto that subject):
function MyEntity()
{
this.Id = 0;
this.Name = "";
}
So the above class has same fields, and in the real world are actually observables which are converted into a json object before persistance, however as there is no C#/BSON layering in nodeJS I was wondering if there was a way to infer what the _id field should be, or if I need to basically make my own mapping mechanic for that?
I only ask as _id is a node specific concern which my business objects should not be constrained to, so I want to keep the same contract style that I would in .net between the service and the callers.