MongoDB export to a comma-separated values file

Posted on

MongoDB by default exports to JSON, but I discovered that it can also export to a comma-separated values (CSV) file. You need to specify a field list. An example with data from the streaming API of Twitter with numerous fields:

mongoexport -d twitter -c tweets --csv -f text,created_at,
  in_reply_to_status_id,coordinates,source,englishness,
  place,in_reply_to_user_id,in_reply_to_screen_name,geo,
  id.floatApprox,user.id,user.followers_count,user.location,
  user.listed_count,user.statuses_count,user.description,
  user.friends_count,user.name,user.lang,user.favourites_count,
  user.screen_name,user.url,user.created_at,user.time_zone,
  user.following -o tweets.csv

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s