0

In example when I use following query

db.adminCommand("listDatabases").databases.forEach( function (d) {
     print ( d.name )
})

I get following result

admin
config
config2
customer1_tnt1
customer2_tnt1

I want to list only those DBs that in result contain string "tnt", because there may be multiple customers and multiple tnt users. How can I achieve that?

Uliysess
  • 579
  • 1
  • 8
  • 19
  • 2
    Umm `db.adminCommand({ "listDatabases": 1, "filter": { "name": { "$regex": "tnt" } }})`. There is note of `filter` [in the documentation](https://docs.mongodb.com/manual/reference/command/listDatabases/) – Neil Lunn Oct 30 '19 at 09:46
  • 2
    FYI, *slightly* changing your question title as a google search [MongoDB listdatabases names using regex](https://www.google.com/search?q=+MongoDB+listdatabases+names+using+regex) (basically using `listdatbases` as a command name instead of separate words ) returns the manual page and the linked duplicate within the top few results. – Neil Lunn Oct 30 '19 at 09:50
  • Yes it does help me together with your first answer. Correctly marked as duplicate – Uliysess Oct 30 '19 at 09:50

0 Answers0