Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to list the collections of a database using a command
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
The JMCNet Team  
View profile  
 More options Oct 15 2012, 2:00 pm
From: The JMCNet Team <the.jmcnet.t...@gmail.com>
Date: Mon, 15 Oct 2012 11:00:04 -0700 (PDT)
Local: Mon, Oct 15 2012 2:00 pm
Subject: How to list the collections of a database using a command

Hi,

I try to list all collections of a database using a client driver. What is
equivalent driver for a "show collections" command in the console ?

----
The JMCNet Team.

Home page, downloads, wiki, support :
http://code.google.com/p/jmcnet-full-mongo-flex-driver/

Forum :
https://groups.google.com/forum/#!forum/jmcnet-full-mongo-flex-driver


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andre de Frere  
View profile  
 More options Oct 15 2012, 9:09 pm
From: Andre de Frere <andre.defr...@10gen.com>
Date: Mon, 15 Oct 2012 18:09:11 -0700 (PDT)
Local: Mon, Oct 15 2012 9:09 pm
Subject: Re: How to list the collections of a database using a command

Hi,

Each of the drivers will do this in a slightly different way, but the
concept remains the same.

For example, in the java driver, you can do "db.getCollectionNames();" as
discussed
at http://www.mongodb.org/display/DOCS/Java+Tutorial#JavaTutorial-Gettin...

In the .Net driver you could use the "GetCollectionNames()" method from the
"MongoDatabase" class, as shown in the API here:
http://api.mongodb.org/csharp/current/html/aa54042b-8014-a9d8-06f0-4b...

Similarly, the PHP driver has a "getCollectionNames"
here: http://www.php.net/manual/en/mongodb.getcollectionnames.php

Inside the Ruby driver, you can get a list of collection names with
"db.collection_names" as discussed in the tutorial
here: http://api.mongodb.org/ruby/current/file.TUTORIAL.html#Getting_a_List...

As mentioned above, the other drivers should have similar functionality in
a way that makes sense for that language.

Hope this helps,
André


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
The JMCNet Team  
View profile  
 More options Oct 16 2012, 1:54 am
From: The JMCNet Team <the.jmcnet.t...@gmail.com>
Date: Mon, 15 Oct 2012 22:54:25 -0700 (PDT)
Local: Tues, Oct 16 2012 1:54 am
Subject: Re: How to list the collections of a database using a command

thank's for your answer, but my question was a little bit tricky. I'm writing a driver (for flash as3) and i wonder how to send a command on mongodb to get in response all collections of a database ?
it couldbe something like : db.$cmd.listCollections or something equivalent.

TheJmcnetTeam.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
The JMCNet Team  
View profile  
 More options Oct 16 2012, 5:17 pm
From: The JMCNet Team <the.jmcnet.t...@gmail.com>
Date: Tue, 16 Oct 2012 14:17:38 -0700 (PDT)
Local: Tues, Oct 16 2012 5:17 pm
Subject: Re: How to list the collections of a database using a command

Hi,

It seems that we can do a query on system.namespaces collection.

But the answer looks like :

{ name:db_name.system.indexes}

{ name:db_name.fs.files}

{ name:db_name.fs.files.$_id_}

{ name:db_name.fs.files.$filename_1_uploadDate_1}

{ name:db_name.fs.chunks}

{ name:db_name.fs.chunks.$_id_}

{ name:db_name.fs.chunks.$files_id_1_n_1}

{ name:db_name.SomeCollection}

{ name:db_name.SomeCollection.$_id_}

So we have to filter the response. Is there a better way to get all
collections of a database ?

Thank's for answer.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William Zola  
View profile  
 More options Oct 16 2012, 9:11 pm
From: William Zola <william.z...@10gen.com>
Date: Tue, 16 Oct 2012 18:11:41 -0700 (PDT)
Local: Tues, Oct 16 2012 9:11 pm
Subject: Re: How to list the collections of a database using a command

Look at the 'listDatabases' command:

 http://docs.mongodb.org/manual/reference/command/listDatabases/

This is the command that all of the drivers end up calling internally.

 -William


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
The JMCNet Team  
View profile  
 More options Oct 17 2012, 7:01 am
From: The JMCNet Team <the.jmcnet.t...@gmail.com>
Date: Wed, 17 Oct 2012 04:01:05 -0700 (PDT)
Local: Wed, Oct 17 2012 7:01 am
Subject: Re: How to list the collections of a database using a command

OK. Thank's. It is exactly what I need.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
The JMCNet Team  
View profile  
 More options Oct 18 2012, 5:08 pm
From: The JMCNet Team <the.jmcnet.t...@gmail.com>
Date: Thu, 18 Oct 2012 14:08:20 -0700 (PDT)
Local: Thurs, Oct 18 2012 5:08 pm
Subject: Re: How to list the collections of a database using a command

Sorry but the listDatabases lists the "databases" and not the collections.
Did I miss something ? Example of listDatabases return :

> use admin

switched to db admin
> db.runCommand({"listDatabases":1})

{
 "databases" : [
 {
 "name" : "test_db",
 "sizeOnDisk" : 83886080,
 "empty" : false
 },
 {
 "name" : "local",
 "sizeOnDisk" : 1,
 "empty" : true
 }
 ],
 "totalSize" : 83886080,
 "ok" : 1
}

Any other idea ? How does the others drivers do to getCollectionNames ?

Thank's in advance.

Le mercredi 17 octobre 2012 03:11:41 UTC+2, William Zola a écrit :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Hernandez  
View profile  
 More options Oct 18 2012, 5:12 pm
From: Scott Hernandez <scotthernan...@gmail.com>
Date: Thu, 18 Oct 2012 17:12:17 -0400
Local: Thurs, Oct 18 2012 5:12 pm
Subject: Re: [mongodb-user] Re: How to list the collections of a database using a command
As with most commands/methods in the mongo javascript shell looking at
the source helps (you can do this by removing the parens):

db.getCollectionNames
function () {
    var all = [];
    var nsLength = this._name.length + 1;
    var c = this.getCollection("system.namespaces").find();
    while (c.hasNext()) {
        var name = c.next().name;
        if (name.indexOf("$") >= 0 && name.indexOf(".oplog.$") < 0) {
            continue;
        }
        all.push(name.substring(nsLength));
    }
    return all.sort();

}

So you want to look at the system.namespaces collection and filter out
the special ones.
On Thu, Oct 18, 2012 at 5:08 PM, The JMCNet Team


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »