我正在使用 node.js
我正在尝试过滤我必须排除集合“出口”并检索所有其他集合的集合,但我似乎无法弄清楚语法。我试过了:
db.listCollections({filter: 'outlets'}).toArray((err, docs)
Run Code Online (Sandbox Code Playgroud)
有什么建议?
您的过滤器构造错误。您不必说“过滤器”,而是必须指定要在过滤器文档中按名称过滤的字段,例如:
db.listCollections({name: 'outlets'});
Run Code Online (Sandbox Code Playgroud)
然而,这将只包括奥特莱斯系列。要排除网点集合,您需要使用$ne 运算符
db.listCollections({name: {$ne: 'outlets'}});
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请参阅有关 listCollections 命令的文档中的指南。