【发布时间】:2023-01-13 18:01:54
【问题描述】:
我想删除除列表之外的所有集合。
db.getCollectionNames().forEach(function(n){db[n].remove({})});
将删除所有集合。
db.getCollectionNames().filter(function(collection){return! /^((keepthisone)|(andthisone)|(alsokeepthisone))$/.test(collection)});
将列出所有收藏,除了我想保留的那些。
我如何将两者结合起来?
db.getCollectionNames().filter(function(collection){return! /^((keepthisone)|(andthisone)|(alsokeepthisone))$/.test(collection)}).forEach(function(n){db[n].remove({})});
什么也没做。
【问题讨论】:
标签: mongodb mongodb-query