FAQ
I am looking for a way to get the total size of all files stored in a
GridFS collection from the official PHP driver. Assume I have the following
code:

$prefix = 'uploads';
$collection = $db->getGridFS($prefix);

How can I get the size of the files stored in *$collection*? Thanks.

Justin

--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user+unsubscribe@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Justin at Mar 12, 2013 at 6:48 pm
    Bump. Anybody have any ideas?

    Thanks.
    On Sunday, March 10, 2013 6:39:27 PM UTC+1, Justin wrote:

    I am looking for a way to get the total size of all files stored in a
    GridFS collection from the official PHP driver. Assume I have the following
    code:

    $prefix = 'uploads';
    $collection = $db->getGridFS($prefix);

    How can I get the size of the files stored in *$collection*? Thanks.

    Justin
    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Scott Hernandez at Mar 12, 2013 at 6:55 pm
    Just get the stats from the chunks collection. It is where the binary data
    is stored for all files.

    db.uploads.chunks.stats()

    On Tue, Mar 12, 2013 at 2:47 PM, Justin wrote:

    Bump. Anybody have any ideas?

    Thanks.

    On Sunday, March 10, 2013 6:39:27 PM UTC+1, Justin wrote:

    I am looking for a way to get the total size of all files stored in a
    GridFS collection from the official PHP driver. Assume I have the following
    code:

    $prefix = 'uploads';
    $collection = $db->getGridFS($**prefix);

    How can I get the size of the files stored in *$collection*? Thanks.

    Justin
    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups
    "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Justin at Mar 12, 2013 at 7:16 pm
    Scott,

    Actually the following worked:

    $files = $mongo_grid_fs->find();
    $total_bytes = 0;
    foreach($files as $file) {
    $total_bytes += $file->getSize();
    }

    return $total_bytes;

    Is this the best way, or would be calling stats() faster and more efficient?
    On Tuesday, March 12, 2013 7:54:40 PM UTC+1, Scott Hernandez wrote:

    Just get the stats from the chunks collection. It is where the binary data
    is stored for all files.

    db.uploads.chunks.stats()


    On Tue, Mar 12, 2013 at 2:47 PM, Justin <comm...@nodesocket.com<javascript:>
    wrote:
    Bump. Anybody have any ideas?

    Thanks.

    On Sunday, March 10, 2013 6:39:27 PM UTC+1, Justin wrote:

    I am looking for a way to get the total size of all files stored in a
    GridFS collection from the official PHP driver. Assume I have the following
    code:

    $prefix = 'uploads';
    $collection = $db->getGridFS($**prefix);

    How can I get the size of the files stored in *$collection*? Thanks.

    Justin
    --
    --
    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<javascript:>
    To unsubscribe from this group, send email to
    mongodb-user...@googlegroups.com <javascript:>
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups
    "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to mongodb-user...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Scott Hernandez at Mar 12, 2013 at 7:20 pm
    Calling stats() does not require any calculations nor looking at any data.
    It is stored in the details of the collection metadata.

    On Tue, Mar 12, 2013 at 3:16 PM, Justin wrote:

    Scott,

    Actually the following worked:

    $files = $mongo_grid_fs->find();
    $total_bytes = 0;
    foreach($files as $file) {
    $total_bytes += $file->getSize();
    }

    return $total_bytes;

    Is this the best way, or would be calling stats() faster and more
    efficient?
    On Tuesday, March 12, 2013 7:54:40 PM UTC+1, Scott Hernandez wrote:

    Just get the stats from the chunks collection. It is where the binary
    data is stored for all files.

    db.uploads.chunks.stats()

    On Tue, Mar 12, 2013 at 2:47 PM, Justin wrote:

    Bump. Anybody have any ideas?

    Thanks.

    On Sunday, March 10, 2013 6:39:27 PM UTC+1, Justin wrote:

    I am looking for a way to get the total size of all files stored in a
    GridFS collection from the official PHP driver. Assume I have the following
    code:

    $prefix = 'uploads';
    $collection = $db->getGridFS($****prefix);

    How can I get the size of the files stored in *$collection*? Thanks.

    Justin
    --
    --
    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

    ---
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to mongodb-user...@**googlegroups.com.

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .

    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups
    "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmongodb-user @
categoriesmongodb
postedMar 10, '13 at 5:39p
activeMar 12, '13 at 7:20p
posts5
users2
websitemongodb.org
irc#mongodb

2 users in discussion

Justin: 3 posts Scott Hernandez: 2 posts

People

Translate

site design / logo © 2021 Grokbase