optimization - mongoDB references fetching takes time -


i use mongoengine object-document mapper. here brief description of collections causing problem. each document in collection a, can have list of references documents in collection b.

class a(document):      list_b = listfield(embeddeddocumentfield(eb))     #other fields not mentioned.  class eb(embeddeddocument):     b_reference = referencefield('b')     loc = geopointfield()  class b(document):     name = stringfield()     #other fields not mentioned. 

when try access list objects of particular document

document_of_a.list_b

the execution time of above line depends on no.of references present in list. eg. takes 100ms 100 references in list.

is there better way fetch references?, execution time of above mentioned line reduced.

you should use select_related flag when querying if want references quickly. please note reference lookups cost queries , select_related() designed reduce number of round trips mongodb.

# single document lookup document_of_a.select_related(2)  # queryset a.objects.select_related(2) 

why 2 select_related lookup? recursive depth is:

  1. look references in list itself
  2. looking references in individual embedded documents

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -