当我使用 show collections 时,它返回一个相当长的所有集合的列表,如何编写查询来返回与模式匹配的集合。我希望有像 db.collections({name:/pattern/}) 这样的东西,但找不到
您可以使用db.getCollectionNames() http://docs.mongodb.org/manual/reference/method/db.getCollectionNames/ with Array.filter() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter:
db.getCollectionNames().filter(function (collection) { return /pattern/.test(collection) })
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)