mongoexport with php

1,535 views
Skip to first unread message

dab

unread,
Apr 11, 2012, 10:48:34 AM4/11/12
to mongodb-user
Hello Guys,

I am trying to export mongodb collection via Php code but looks like
it doesn't work,
Here is the code i am using.

exec("mongoexport -d test -c foo -o /web/www/cloud1/MongoDump/
foo.json") or die('Export Failed');

But as I run same command on linux cli, it does work.

Any example will be helpful.

Thanks!

Kristina Chodorow

unread,
Apr 11, 2012, 12:16:02 PM4/11/12
to mongodb-user
Can you run:

$output = array();
$ret = null;
exec("mongoexport -d test -c foo -o /web/www/cloud1/MongoDump/
foo.json", $output, $ret);
var_dump($output, $ret);

and paste the result?

dab

unread,
Apr 11, 2012, 12:46:21 PM4/11/12
to mongodb-user
Thanks for your reply, but luckily script worked and data was also
saved in .json file but somehow I was not getting right output.


here the out put of your shared code:

array(0) { } int(0)

but data saved in foo.json file:
{ "_id" : { "$oid" : "4f687deca3bcdf691b668bfe" }, "name" : "sara" }


Thanks for your reply.


On Apr 11, 6:16 pm, Kristina Chodorow <krist...@10gen.com> wrote:
> Can you run:
>
> $output = array();
> $ret = null;
> exec("mongoexport-d test -c foo -o /web/www/cloud1/MongoDump/
> foo.json", $output, $ret);
> var_dump($output, $ret);
>
> and paste the result?
>
> On Apr 11, 10:48 am, dab <cont...@danyalbutt.com> wrote:
>
>
>
>
>
>
>
> > Hello Guys,
>
> > I am trying to export mongodb collection viaPhpcode but looks like
> > it doesn't work,
> > Here is the code i am using.
>
> > exec("mongoexport-d test -c foo -o /web/www/cloud1/MongoDump/

Kristina Chodorow

unread,
Apr 11, 2012, 4:44:45 PM4/11/12
to mongodb-user
Glad it worked out.

Sam Millman

unread,
Apr 11, 2012, 4:51:34 PM4/11/12
to mongod...@googlegroups.com
Mongoexport wont output to terminal in this case hence you get no response from the terminal command.

Glad it worked out.
--
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.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


sanjiv upadhyaya

unread,
Sep 18, 2013, 5:20:05 PM9/18/13
to mongod...@googlegroups.com
Hi Kristina ,

Your code is working and a file foo.json is also being created... but the thing is the file is emply and has no data in it.. in the terminal I get array(0) { } int(0) ..

Is there something I am missing here... thanks a lot in advance

Hannes Magnusson

unread,
Oct 21, 2013, 9:10:30 PM10/21/13
to mongod...@googlegroups.com
Are you running this script on the same server as the mongod is running on?
Could you try running the command normally on the command line, rather then through PHP to see what is going on?
Also, did you make any changes to the script, or your mongod setup?

-Hannes
Reply all
Reply to author
Forward
0 new messages