I'm writing my first application whit NoSql Db ( Mongo ); I usually use the DAO pattern to connect the business layer with the model, but I'm facing some problems in apply it to Mongo, in particoular when there are sub-document objects; let's say that I have an object A that has a list of object B;
{
"id":1,
"name":"xyz",
"listOfB": [
{
"id":2,
"index": 7
},
{
"id":3,
"index": 12
}
]
}
Usually, when dealing whit relational db, I have a DAO class for each object in the model, and each object maps a single table into the db; but I don't know exactlywhat to do whit mongo: I have created a DAO class for object A ( in general, a DAO for every objects that rapresents a Document on the Db), but I don't know exactly what to do whit objects B; objects B doesn't exist by itself, but always as a part of other objects like A or others (C, D ecc.): have I to write a DAO for every relation ( like B_Inside_A_DAO, B_inside_C_DAO ecc.)? Or have I to write the methods to access/modify B object inside the DAO of the main document ( for example if I have to read a B object inside A, I add the method in A_DAO)? Or maybe there is another pattern that is specific fo NoSql access?
Thanks.
Aucun commentaire:
Enregistrer un commentaire