Re: [mongodb-user] Using mongoexport within pymongo

2,359 views
Skip to first unread message

Bernie Hackett

unread,
Dec 21, 2012, 2:57:18 PM12/21/12
to mongod...@googlegroups.com
I'm not sure I understand the question. Are you just trying to convert
the python dictionaries you get back from PyMongo to JSON documents?
If so just use json_util:

http://api.mongodb.org/python/current/api/bson/json_util.html

If you have Binary fields in your documents make sure you use the
latest version of PyMongo (2.4.1 as of this writing).

On Fri, Dec 21, 2012 at 11:02 AM, Ajay Muppuri <ajay....@gmail.com> wrote:
> Hello,
>
> Is it possible to use mongoexport in json in python? I have a large set of
> documents within my mongodb collection and writing to a file takes a fair
> bit of time. I was wondering if I could run mongoexport within the python
> code on that collection to export it as json.
>
>
> Ajay
>
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb

Ajay Muppuri

unread,
Dec 21, 2012, 6:21:10 PM12/21/12
to mongod...@googlegroups.com
Yes. my main problem is generating json files. 

So the code is like this Connect to db-> get list od collections by regex -> Get all documents in those collections -> convert to json -> write to output file. But this process takes a fair bit of time, whereas I felt mongoexport was much more quicker. Thats why i was looking if these is a more optimum solution that I can use.

Ajaay

Bernie Hackett

unread,
Apr 8, 2013, 9:52:25 PM4/8/13
to mongod...@googlegroups.com
This thread is pretty old but why not just use mongoexport by itself? By default mongoexport exports data in json format. PyMongo has no interface to mongoexport. If you want to script things with python you could just call mongoexport using python's subprocess.Popen:
Reply all
Reply to author
Forward
0 new messages