Hi All,
I am new to MongoDB, and Jongo / Morphia.
Trying to get hands on with the mapping concept in MongoDB using , Java and Jongo / Morphia Unable to figure out how to establish mapping relationship between entities.
Can someone please help me out with some example ?
For example :
I have a json
{
"name": "abc",
"password": "xyz",
"address": {
"street": "ghgjk",
"pin": 25646
},
"readingHabbits": ["jkjsdj", "sdkhks", "jlcsd"],
"eatingHabbits": {
"internalObjOne": {
"dkks": "jdskdfl",
"lfld": "hfslvlsk"
},
"internalObjectSecond": {
"cjdlksl": "hcdkjnjkcs",
"cjsdjljsl": "chsdskjc"
}
}
}
For above json I created some classes.
Base class :-
@Document(collection="user")
public class User{
@Id
private String id;
private String name;
private String password;
@DBRef
private Address address;
@DBRef
private ReadingHabbits readingHabbits;
//setter and getter
}
@Document(collection="address")
public class Address{
@Id
private String id;
private String street;
private int pin;
//setter and getter
}
Do we need to create separate classes for "ReadingHabbits" and "EatingHabbits" ?
If not then is the above approach correct to map two different entities with DBRef and save it to two different collection in MongoDB using Jongo?
Or do we have any other way to do the same operation ?
Thanks In Advance..... :)