.net - How can I make this MongoDB query more efficient? -


just simple query looking @ list of objects passed in , finding values match. aobjects list of aobjects.

var queries = aobjects     .select(g =>         query.and(             query<bobject>.eq(m => m.sourcekey, g.sourcekey),             query<bobject>.eq(m => m.sourcetypeid, g.sourcetypeid)         )     )     .tolist();  var query = query.or(queries);  var result = collection.find(query).tolist();  return result; 

right when run query large set of aobjects (2500,7500) query takes extremely long time; 1 , 8 minutes respectively.

both sourcekey , sourcetypeid indexed bobject's collection.

i feel there should better way build query make more efficient, i'm of noob when comes nosql query optimization.

thanks.

mongodb (like databases) can't use more single index @ time (unless it's or query). means although maintain 2 indexes 1 chosen , used.

to build index specific query need compound index of both "sourcekey" , "sourcetypeid":

aobjects.createindex(indexkeys<aobject>.ascending(_ => _.sourcekey).ascending(_ => _.sourcetypeid) 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -