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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:32:54+00:00 2026-06-17T02:32:54+00:00

I have data in an mongo collection called hello. The documents look like: {

  • 0

I have data in an mongo collection called “hello”. The documents look like:

{ 
name: ..., 
size: ..., 
timestamp: ISODate("2013-01-09T21:04:12Z"), 
data: { text:..., place:...},
other: ...
}

I would like to export the timestamp and the text from each document into a CSV File, with first column the Timestamp and second column the text.

I tried creating a new collection (hello2) where the documents only have the timestamp and the text.

data = db.hello
for i in data:
    try:
        connection.me.hello2.insert(i["data"]["text"], i["timestamp"])
    except:
        print "Unable", sys.exc_info()

I then wanted to use mongoexport:

mongoexport --db me --collection hello2 --csv --out /Dropbox/me/hello2.csv

But this is not working and I do not know how to proceed.

PS: I would also like to store only the time of the ISODate in the CSV File, i.e. just 21:04:12 instead of ISODate(“2013-01-09T21:04:12Z”)

Thank you for your help.

  • 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-17T02:32:56+00:00Added an answer on June 17, 2026 at 2:32 am

    You can export right from the data collection, no need for a temporary collection:

    for r in db.hello.find(fields=['text', 'timestamp']):
         print '"%s","%s"' % (r['text'], r['timestamp'].strftime('%H:%M:%S'))
    

    or to write to a file:

    with open(output, 'w') as fp:
       for r in db.hello.find(fields=['text', 'timestamp']):
           print >>fp, '"%s","%s"' % (r['text'], r['timestamp'].strftime('%H:%M:%S'))
    

    To filter out duplicates and print only most recent ones, the process should be split in two steps. First, accumulate data in a dictionary:

    recs = {}
    for r in d.foo.find(fields=['data', 'timestamp']):
        text, time = r['data']['text'], r['timestamp']
        if text not in recs or recs[text] < time:
            recs[text] = time
    

    and then output the dictionary content:

    for text, time in recs.items():
        print '"%s","%s"' % (text, time.strftime('%H:%M:%S'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Mongo collection called documents which has the following structure: { name:
If I have data in my users collection that looks like: { name: '...',
I have a collection in mongo in which I am inserting data from Perl
i have a mongo collection like this: { A2_AboutMe: , A2_Attributes: |av|nv|, A2_Birthday: ,
I have a necessity to remove all data from mongo collection. Droping of collection
I have a collection in mongo which has name and count fields. {name:'myName',count:5} Is
I am storing book meta-data like name,authors,price,publisher,etc in a mongodb document. I have about
The problem is: I have 3 mongo tables, and I want to migrate data
I have data like the following: var data = [{ id: 1, date: new
I have an application that use mongo for storing short living data. All data

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.