Intersection of sets Mongodb
Posted
by afvasd
on Stack Overflow
See other posts from Stack Overflow
or by afvasd
Published on 2010-05-24T07:14:26Z
Indexed on
2010/05/24
7:21 UTC
Read the original article
Hit count: 276
mongodb
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?
© Stack Overflow or respective owner