Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 998235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:09:42+00:00 2026-05-16T07:09:42+00:00

I have a collection which is an action log between two users. It has

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:09:42+00:00Added an answer on May 16, 2026 at 7:09 am

    The $or operator is available in MongoDB 1.5.3 and later.

    An alternative is to use a Javascript function, something like…

    find = self.db.action_log.find()
    find.where(pymongo.code.Code('this.dest_id==1 || this.src_id==2'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list: Collection users which has around 100K+ records of users (all
I have a mongo collection which has documents with two fields fieldA and fieldB,
I have this div in my rails view which renders a collection of users:
I have an ItemEntity class, which has a collection of ImageEntity's. I want to
We are currently implementing a solution where we have a collection which we want
I have an event collection which I'm going through to find a category to
I have the following collection which i would like to bind to a combobox:
In my application, I have three collection objects which store data. The data which
I have a collection of objects which describe an image-name, its size and it's
I have a collection of arrays which are generated dynamically. What I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.