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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:58:53+00:00 2026-06-09T21:58:53+00:00

I am interested in printing a range of query. I have the following code.

  • 0

I am interested in printing a range of query. I have the following code.

start = datetime.datetime(2012, 2, 2, 6, 35, 6, 764) 

end = datetime.datetime(2012, 2, 2, 6, 55, 3, 381) 

for doc in db.model.find({'time': {'$gte': start, '$lt': end}}): 
    print doc 

It does the job, printing out basically how I inserted the data.

My question is this:

Is it possible to print out one element of the whole query? Such as, I want it to only print the item or the date or another input inserted, not give me {‘time’: datetime.datime(….), ‘input1’: …, ‘item’: …}. Otherwise, it would greatly slow my program if I had to reparse the mongodb query data I have already parsed to put into mongodb.

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-06-09T21:58:55+00:00Added an answer on June 9, 2026 at 9:58 pm

    Let’s have some basics about how pymongo works.

    Let’s assume you have some collection in Mongo with inserted data. You want to get data from that collection by making queries:

    cursor = db.model.find({'time': {'$gte': start, '$lt': end}})
    

    Method find of “model” collection object returns Cursor object: an entity that holds all info about the query and query results.

    So the query is made, and the next step is getting results. Result types of Mongo queries can differ from method to method. In our case (find method) – result is a bunch of JSON objects (iterator object), each of them is represented by dict type in Python language. It means that you don’t have to parse results: they are already parsed into dicts.

    Another thing about Cursor: it is lazy. It means that you receive results on demand. In case of Cursor object, you must iterate through it to get object fetched with query:

    for result_object in cursor:
        print result_object   # result_object is a dict that holds JSON object
        result_object['_id']  # Mongo ObjectId of the result_object
        # result_object["<field_name>"]  # Value stored in a field named <fieldname>
    

    Generally, you have to try reading Pymongo Tutorial: it’s quite short and gives direction of how the whole driver works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am interested in theoretical Big-O analysis of the following MySQL query: SELECT id,
I am interested in doing this C code in Java: // sets n's ith
I used to have postcript printing working perfectly in Emacs 21 in Windows+Cygwin, but
Interested in upgrading JAVA VERSION from JAVA 1.5 to JAVA 1.6 [oracle@server301 /]$ java
I interested to work with data types and file formats. For example I want
im interested how many api calls per second or per minute i can do
As i am Interested in artificial intelligence, I recently decided to give Lisp a
I'm interested in making ghost preview elements of very complex DOM objects. While I
I am interested in knowing about what other teams are doing about limiting internal
I am interested in logging all traffic that comes over port 443 for trouble-shooting

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.