
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How to get all collections where collection name like '%2015%'?
Let us first create some collections that starts from year number i.e. 2015, 2019, etc −
> use web; switched to db web > db.createCollection("2015-myCollection"); { "ok" : 1 } > db.createCollection("2019-employeeCollection"); { "ok" : 1 } > db.createCollection("2015-yourCollection"); { "ok" : 1 }
Now you can display all the collections with the help of SHOW −
> show collections;
This will produce the following output −
2015-myCollection 2015-yourCollection 2019-employeeCollection applyConditionDemo check creatingAliasDemo emp_info emptyCollection removeNullDemo
Following is the query to get all collections where collection name like ‘%2015%’ −
> db.getCollectionNames().filter(function (v) { return /^2015\-/.test(v); })
This will produce the following output −
[ "2015-myCollection", "2015-yourCollection" ]
If you want to check collection name beginning with 2019, implement the below query −
> db.getCollectionNames().filter(function (v) { return /^2019\-/.test(v); })
This will produce the following output −
[ "2019-employeeCollection" ]
- Related Articles
- How to get all the collections from all the MongoDB databases?
- How to aggregate two collections where a field from one collection is greater than the other in MongoDB?
- Removing all collections whose name matches a string in MongoDB
- Differences between Collection and Collections in Java?
- Difference between collection and collections in java
- How to list all collections in the Mongo shell?
- Get all fields names in a MongoDB collection?
- How to list all collections from a particular MongoDB database?
- How to remove all elements from a Collection in another Collection
- Get names of all keys in the MongoDB collection?
- Get all results using WHERE clause in MySQL?
- How to get details of a webpage like url, title name, domain name etc using Javascript Executor in Selenium?
- State which of the following collections are sets.1.Collection of first three days of a week2. Collection of alto students of your class3. Collection of all lovely flowers
- How to list all the Collections in a MongoDB database using Java?
- How to get array from a MongoDB collection?

Advertisements