MongoDB skip & limit when querying two collections -


let's have 2 collections, , b, , single document in related n documents in b. example, schemas this:

collection a: {id: (int),  propa1: (int),  propa2: (boolean) } collection b: {ida: (int), # id document in collection  propb1: (int),  propb2: (...),  ...  propbn: (...) } 

i want return properties propb2-bn , propa2 api, , return information (for example) propa2 = true, propb6 = 42, , propb1 = propa1.

this simple - query collection b find documents propb6 = 42, collect ida values result, query collection values, , filter results collection documents query.

however, adding skip , limit parameters seems impossible while keeping behavior users expect. naively applying skip , limit first query means that, since filtering occurs after query, less limit documents returned. worse, in cases no documents returned when there still documents in collection read. example, if limit 10 , first 10 collection b documents returned pointed document in collection propa2 = false, function return nothing. user assume there's nothing left read, may not case.

a less naive solution check if return count < limit, , if so, repeat queries until return count = limit. problem here skip/limit queries user expect exclusive sets of documents returned return same documents.

i want apply skip , limit @ mongo query level, not @ api level, because results of querying collection b large.

mapreduce , aggregation framework appear work on single collection, don't appear alternatives.

this seems that'd come lot in mongo use - ideas/hints appreciated.

note these posts ask similar sounding questions don't address issues raised here.

sounds have solution (2).

you cannot optimize/skip/limit on first query, depending on search can perhaps on second query.

you need loop around either way, write.

i suppose, .skip costly you, since need results , throw them away, simulate skip, give user consistent behavior.

all logic have go loop - unless can match in clever way second query (depending on requirements).

out of curiosity: given time passed, should have solution now?!


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -