I have a collection which is an action log between two users. It has a src_id and a dest_id.
I'm a looking to fetch all the records that are actions between id1 and a list of ids - "ids = [id2, id3, id4]".
The following two statements work properly:
act_obs = self.db.action_log.find(
{'src_id': id1, 'dest_id': {'$in': ids} }
)
act_obs = self.db.action_log.find(
{'dest_id': id1, 'src_id': {'$in': ids} }
)
However, and this is where I can't figure out what is wrong, the following refuses to return any results at all:
act_obs = self.db.action_log.find(
{'$or': [
{'dest_id': id1, 'src_id': {'$in': ids} },
{'src_id': id1, 'dest_id': {'$in': ids} }
]}
)
Can someone shed some light on what I'm doing wrong, if that is the case? And more importantly, how to accomplish what I'm trying to do within mongo.
I'm trying to get all the records where id1 is the src_id and any of the ids in the ids list is the dest_id OR any records where id1 is the dest_id and any of the ids in the ids list is the src_id.
I'm using pymongo 1.7. Thank you!