java - How to retrieve @Reference fields / which is best @Reference or @Embedded and SubQuery in MorphiaQuery -


i have mongodb 2 model classes user , userinfo.... criteria in user class have retrieve multiple fields around 10 fields "firstname","lastname",etc , in userinfo model class retrieve 1 field "age".

at moment referenced userinfo class's object user class stated below in structure , stores in db {"firstname","john"},{"lastname","nash"},{userinfo: userinfoid} if make embedded relation store userinfo's fields , think retrieve 1 ("age") field unwanted embed userinfo's fields inturn make application slow think.

can please guide me scenario use whether @reference or @embedded, think embedded slow down response db in websites given reference annotation slows down querying time , needs sort of lazy loading all, structure below:

class user extends model{  public string firstname;  public string lastname;  public string logintime;  public string logouttime;  public string emailid; etc,etc......   more 10 fields this+userinfo reference object    @reference   public userinfo userinfo;   }      class userinfo extends model{  public string emailid;  public string age;  public string sex;  public string address;  public string bank; etc,etc......  more 10 fields   }    

as stated above want age field userinfo , all fields of user, annotation best , @reference or @embedded. more helpful if i single query user class in can retrieve fields of user , "age" field of userinfo , tell in short need query this when go @reference relationship

field("userinfo.age") userinfo.emailid = (morphiaquery q =        user.createmorphiaquery;             q.field("firstname").equal("john");     q.field("lastname").equal("nash");                                             q.field("logintime").greaterthan("sometime"))//the complex part need age of particular userinfo have id of userinfo since iam using reference , id got **subquery**....  

please dont write 2 queries need single query or maybe query subquery: more clear can tell in sql language :

   select age userinfo emailid = u.emailid    (select * user firstname='john' , lastname='nash' ,        logintime='sometime') u;     

i need exact same query without writing 2 morphia queries consumes more time referring 2 tables please guide me pls reply asap ... in advance :there in internet find answer, please genius guide me or give me proper answer:) little urgent please !!!!

mongo not support query across tables / collections. , such page satisfy you:

mongodb , "joins"

as in sql, join query build intermediate result set , make query again:

understanding how join works when 3 or more tables involved. [sql]

when build model, should not consider lot single query structural modeling:

http://docs.mongodb.org/manual/core/data-modeling/

for case, if using embeded, can make in 1 query , specify fields need using queries like:

db.user.find({"some_field":"some_query"},{"firstname":1,....,"userinfo.age":1}) 

check projections here:

http://docs.mongodb.org/manual/reference/method/db.collection.find/

if using reference or soft link using morphia key<> lazy load userinfo, requires 2 queries.

if it's not real-time application, can try mongo map-reduce merge collection handle big data, though map-reduce bad mongo though.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -