Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get collection names in the database? #157

Open
BlaCatRu opened this issue Feb 2, 2017 · 5 comments
Open

How to get collection names in the database? #157

BlaCatRu opened this issue Feb 2, 2017 · 5 comments

Comments

@BlaCatRu
Copy link

BlaCatRu commented Feb 2, 2017

Help pls

  • "mc_worker_api:command(Connection,{<<"listDatabases">>,1})" works fine and returns a basic info about all existing databases
  • but listCollections command has another output and returns the cursor and the first batch

How cat I get results similar to the db.getCollectionNames method?

@comtihon
Copy link
Owner

comtihon commented Feb 2, 2017

Hi,
You can get all the results from cursor by calling mc_cursor:rest/1

@BlaCatRu
Copy link
Author

BlaCatRu commented Feb 3, 2017

Hi,
There is another kind of the cursor i think.
And mc_cursor:rest/1 fails :-(

{ok,<0.120.0>}
2> {true, Res} = mc_worker_api:command(Connection,{<<"listCollections">>,1}).
{true,#{<<"cursor">> => #{<<"firstBatch">> => [#{<<"idIndex">> => #{<<"key">> => #{<<"_id">> => 1},
               <<"name">> => <<"_id_">>,
               <<"ns">> => <<"xxxdb.xxx.collection">>,
               <<"v">> => 1},
             <<"info">> => #{<<"readOnly">> => false},
             <<"name">> => <<"xxx.collection">>,
             <<"options">> => #{},
             <<"type">> => <<"collection">>},
           #{<<"idIndex">> => #{<<"key">> => #{<<"_id">> => 1},
               <<"name">> => <<"_id_">>,
               <<"ns">> => <<"xxxdb.xxx.collection">>,
               <<"v">> => 1},
             <<"info">> => #{<<"readOnly">> => false},
             <<"name">> => <<"xxx.collection">>,
             <<"options">> => #{},
             <<"type">> => <<"collection">>}],
          <<"id">> => 0,
          <<"ns">> => <<"xxxdb.$cmd.listCollections">>}}}
3> mc_cursor:rest(Res).
** exception exit: {{function_clause,[{gen,do_for_proc,
...```

Description of this cursor from docs:
**listCollections.cursor**
A document that contains information with which to create a cursor to documents that contain    collection names and options. The cursor information includes the cursor id, the full namespace for the command, as well as the first batch of results.

@comtihon
Copy link
Owner

comtihon commented Feb 6, 2017

Thanks, I'll check it.

@dmsnell
Copy link
Contributor

dmsnell commented Nov 18, 2020

@BlaCatRu did you ever figure it out?

@dmsnell
Copy link
Contributor

dmsnell commented Dec 16, 2020

From my own exploration I believe that the response is returning the full list of collections inside of the <<"firstBatch">> field. I tried this on a database with a few hundred collections and it never indicated that there were more batches. Also the cursor id returned from the query seems to be invalid. I believe this is a special case for the commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants