Intersection of sets Mongodb
- by afvasd
Hi everyone
I am new to mongo, this is my db design:
product := {
name: str
group: ref,
comments: [ ref, ref, ref, ref ]
}
comments := {
... a bunch of comments stuff
}
tag := {
_id: int, #Need this for online requests
tag: str,
products: [ {product: ref, score: float}, ... ],
comments: [ {comment: ref, score: float}, ...],
}
So my usage pattern is:
GIVEN a product, find comments that have certain tag and sort them accordingly.
My current approach involves:
Look for that tag object that has
tag=myTag
pull all the comments out, sorted
look for that product where
product.name=myProduct
pull all the comments out (which are
dbrefs by the way)
loop through the result of 2, and
checking if they are in 4, (this I
can do a limit 10) etc.
It's pretty inefficient. Any better methods?