mongodb - Is there a where like relation function when using pymongo? -
i have following data:
a collection named categories contains documents so:
{ "cat":"films anglais", "path":"w:\\videos" }
categories unique (because use upsert) or let's admit anyway.
a collection named rules contains documents so:
{ "title":"braveheart", "regex":"^.*braveheart.*$", "cat":"films anglais" }
i iterating on rules. can access cat rules rule['cat']. need path categories.
i know can do:
dest = "" category in categories.find(): if category['cat'] == rule['cat']: dest = category['path'] break
1) prefer process database side. categories.find_one().distinct('path').where(cat=rule['cat'])? invalide know.
2) there way define sort of relation not need duplicate cat field?
lastly, have read difference between relationnal , non relationnal systems in case choice sealed.
for 1), don't want use server-side javascript here, or ever, really. it's slow , blocks lots of other operations. don't use server-side javascript try , fake joins in mongodb.
for 2), duplicating path
info rules
documents seems best solution. how path
change? cost embedding path
duplication , need more expensive set of updates if path
changes, compared current setup. seems worth me, in absence of further information use case.
Comments
Post a Comment