York women style Rihanna's new Fenty collection and shop their looks. Rihanna is sartorially known for many things, from being a general. Should You Pay an Old Collection? But it does look better than the alternative. On the other hand, if the debt is going to drop off your credit report in a few months, it may be better to just wait and let it fall off. You Need to Do Business With Them Again.
Active1 year, 4 months ago
i am looking for a particular element in a collection. how do i know if it exists in the collection?
l--'''---------''''''l--'''---------''''''4,268243243 gold badges557557 silver badges903903 bronze badges
5 Answers
If you used a key when you added the item to the collection, see if referring to this key gives an error:
Otherwise you have to loop through all items to see if there's the one you need.
GSergGSerg63.1k1515 gold badges117117 silver badges256256 bronze badges
Collection are index based. Hence, you will have to loop through the collection to search for an item.
shahkalpeshshahkalpesh30k22 gold badges5151 silver badges8282 bronze badges
I use a simple tool function which iterates through a collection. It's without directly accessing indexes and it uses VBA language features like they should be used (Comparison of variants and each-Loop).
Marcucciboy22,53133 gold badges1111 silver badges2626 bronze badges
schmijosschmijos5,06133 gold badges3535 silver badges4242 bronze badges
@Josua Schmid:
I think the code in your answer could be correct but could be not correct as well. Your function has paremeter of type Variant and it is then compared to each menber of the collection. But what is compared actually? In this case the default member is compared. So firts problem could arise if the collection will contain members of some custom class which does not have default member specified. In such case runtime error 438 object doesn't support this property or method will be raised. Well you could add default member but even then it will work in a way you maybe not like I am afraid.
Example with ranges (for Range-Class Value is the default member so Values will be compared). Maybe it is exactly what you wanted but maybe not. So from my point of view better is to use 'Key' for each Item added to collection and then try to get this Item by its Key.
Debug.Print col.item(r1.Address) ' A1 Value
Or by index if no keys were used:
Debug.Print col.item(1) ' A1 Value
Output:
deedee11.1k44 gold badges2626 silver badges4545 bronze badges
It is possible to determine the collection item with a variant. In the example below, I am determining if an object with a specific index exists in the FXItems collection or not. If it doesnt exist, system will create it otherwise, do some other action
Ankur GAnkur G
Not the answer you're looking for? Browse other questions tagged vbacollections or ask your own question.
Active8 months ago
In the MongoDB shell, how do I list all collections for the current database that I'm using?
coffee-grindercoffee-grinder11.8k1717 gold badges5151 silver badges7979 bronze badges
21 Answers
You can do...
JS (shell):
node.js:
non-JS (shell only):
The reason I call that non-JS is because:
If you really want that sweet, sweet
Bruno Bronoskyshow collections
output, you can:40.4k55 gold badges9797 silver badges9797 bronze badges
AdaTheDevAdaTheDev112k2323 gold badges171171 silver badges179179 bronze badges
will list all the collections in the currently selected DB, as stated in the command line help (
CameronCameronhelp
).71.5k1616 gold badges166166 silver badges205205 bronze badges
how do I list all collections for the current database that I'm using?
show collections
show tables
db.getCollectionNames()
To list all databases:
To enter or use given database:
To list all collections:
Output:
(or)
Output:
(or)
Output:
To enter or use given collection
Community♦
Bharadwaja BapatlaBharadwaja Bapatla2,93011 gold badge88 silver badges1313 bronze badges
> show tables
It gives the same result as Cameron's answer.
Kevin MeredithKevin Meredith17.7k4949 gold badges155155 silver badges297297 bronze badges
Apart from the options suggested by other people:
There is also another way which can be really handy if you want to know how each of the collections was created (for example it is a capped collection with a particular size)
Salvador DaliSalvador Dali129k9292 gold badges539539 silver badges641641 bronze badges
First you need to use a database to show all collection/tables inside it.
Tarun GuptaTarun Gupta5,27422 gold badges2828 silver badges3737 bronze badges
lxglxg
Luksprog82.2k1616 gold badges180180 silver badges179179 bronze badges
Indrajeet SinghIndrajeet Singh
The command used for displaying all the collection in the mongoDb database is
Before running the show collections command you have to select the database
To see all the databases you can use the command
For more info visit this link : http://docs.mongodb.org/manual/tutorial/getting-started/
kkkkkk1,17111 gold badge1616 silver badges3333 bronze badges
If you want to show all collections from mongodb shell (command line), use shell helper
that show all collections for current database.If you want to get all collection list from your application then you can use mongodb database method
For more info mongodb shell helper you can seee http://docs.mongodb.org/manual/reference/mongo-shell/
Engr. Hasanuzzaman SumonEngr. Hasanuzzaman Sumon1,47533 gold badges2121 silver badges3535 bronze badges
The following commands on mongoshell are common
Also,
Sometimes it's useful to see all collections as well as the indexes on the collections which are part of the overall namespace:
Here's how you would do that:
Between the 3 commands and this snippet you should be well covered!
SoodSood
I think one of the biggest confusions is the difference between what you can do with
mongo
(or an interactive/hybrid shell) vs. mongo --eval
(or a pure javascript shell). I keep these helpful documents handy:Here is an example of scripting what you might otherwise do with
show
commands:Note: That works really well as a oneliner. (But looks terrible on StackOverflow.)
Bruno BronoskyBruno Bronosky40.4k55 gold badges9797 silver badges9797 bronze badges
Aniruddh JoshiAniruddh Joshi6,71811 gold badge2020 silver badges4343 bronze badges
For switch to the database.by:- use {your_database_name} example:
where friends is the name of your database.
then write:-
this will give you the name of collections.
Shashikant PanditShashikant Pandit
List all collections from the mongo shell :
- db.getCollectionNames()
- show collections
- show tables
Note : Collections will show from current database where you are incurrently
Hasib KamalHasib Kamal
- connect with mongo database using
mongo
, this will start the connection. - then run
show dbs
command, this will show you all exiting/available database. - then select the
database
you want.in above it isanuradhfirst
, then runuse anuradhfirst
.this will switch to the database you want. - then run
show collections
command, this will show all thecollections
inside your selected database.
3,25744 gold badges2828 silver badges5353 bronze badges
show collections
this command usually works on mongo shell once you have switched to the database.
PHINCY L PIOUSPHINCY L PIOUS
For MongoDB 3.0 deployments using the WiredTiger storage engine, if you run
db.getCollectionNames()
from a version of the mongo shell before 3.0 or a version of the driver prior to 3.0 compatible version, db.getCollectionNames()
will return no data, even if there are existing collections.For further details, please refer to this
RahulRahul12.4k33 gold badges2929 silver badges5555 bronze badges
Details information of every collection
- For users with the required access (privileges that grantlistCollections action on the database), the method lists the namesof all collections for the database.
- For users without the required access, the method lists only thecollections for which the users has privileges. For example, if auser has find on a specific collection in a database, the methodwould return just that collection.
AmiteshAmitesh
I use
listCollections
(supports mongo 3.0 and up) for this purpose.example:
To fetch more info like index of the collection:
To print just the collection names:
I feel this provide more flexibility.
read more: https://docs.mongodb.com/manual/reference/command/listCollections/
Sahith VibudhiSahith Vibudhi
use following command from mongo shell :-show collections
Anoop SharmaAnoop Sharma
protected by JohnnyHKJan 12 '15 at 19:10
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?