show collections 問題
-
使用 show collections 會出現一堆 collection,想請問有沒有什麼方式可以很快的找到的指定名稱,像是 mysql 的 show tables like '%test%' 之類的 ?
-
可以使用 db.getCollectionInfos()
例如:
db.getCollectionInfos({name:/test/})
或者
db.getCollectionInfos({name:{$regex:'test'}})
-
實用好文
-
@neo\
很實用的例子, 值得收藏
-
也可以使用 db.getCollectionNames(),再透過 javascript 的 filter 來選擇 collection
例如:
db.getCollectionNames().filter(function(el) {return el.indexOf('test') !== -1})
-
學習了~ 感謝解答~
-
學習了~ 感謝解答~