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 6694395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:05:48+00:00 2026-05-26T06:05:48+00:00

EDIT: I have somewhat distilled the question. mongo_documents = mongo_collection.find({medicalObjectId: 269}) print \n\n for

  • 0

EDIT:
I have somewhat distilled the question.

mongo_documents = mongo_collection.find({"medicalObjectId": "269"})
print "\n\n"
for this_document in mongo_documents:
    print this_document

print "-------------------------"

pqr = 269
mongo_documents2 = mongo_collection.find({"medicalObjectId": pqr})
print "\n\n"
for this_document2 in mongo_documents2:
    print this_document2

My problem is that the first code chunk where I use the number as the key in the query, works. But the second chunk where I use the variable, i get no output.


I am a beginner at python and pymongo, so please bear with me.

I have a list as;
row = [1, 2, …., 100]

I want to query a mongodb collection for each entry in my list.
The collection has the format:
collection = {‘pk’, ‘attribute1’, ‘attribute2’, ‘attribute3’}

I want to call the mongodb connection and iterate through each entry in my list with row[i]=pk and return the other attributes as the output.

ie. mongo_documents = mongo_collection.find({‘pk’ : row[0]})
mongo_documents = mongo_collection.find({‘pk’ : row[1]})
and so on.

The code that I have is:

for row in result_set:
    print row[0]
    mongo_documents = mongo_collection.find({'medicalObjectId' : row[0]})
    print mongo_documents
    for this_document in mongo_documents:
        print "----------------------------------"
        print this_document

however i get no output. where am I going wrong?
if i print mongo_documents, i get

    <pymongo.cursor.Cursor object at 0xe43150>
  • 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-26T06:05:49+00:00Added an answer on May 26, 2026 at 6:05 am

    You could use the $in operator of mongodb to fetch all the rows at once and iterate through them.

    mongo_documents = mongo_collection.find({ 'medicalObjectId' : { '$in' : result_set } } );
    for doc in mongo_documents:
        print mongo_documents
    

    I have not tested it, comment below if it doesnt work.

    EDIT

    mongo_documents2 = mongo_collection.find({"medicalObjectId": str(pqr)}) 
    print "\n\n" 
    for this_document2 in mongo_documents2: 
        print this_document2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I have changed the question as it was too localized and gained negative
I have somewhat of a strange question that is not really technical, but I
I have a somewhat complicated question related to MySQL. This is the table I
I've researched the subject somewhat before posting the question, but I couldn't find the
EDIT I have finally figured out the problem i have been having on my
EDIT: I have fixed all but two warnings now, so thank you all for
EDIT: I have edited my post... Working on a project (c#), I have a
EDIT i have something like this in a file: imagecolor=0 arrayimagecolorcopy=0 arrayimagecolorcopy3d=0 when i
EDIT: I have realized the source of my problem. I only have count information
I won't want to have edit any working sets. I just want a way

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.