mongoDB过滤listCollections方法

时间:2018-02-06 05:30:22

标签: mongodb

你好我想列出Mongodb上的所有收藏品,除了两个名为“logos”和“outlet”的收藏品,但我似乎无法弄明白。

这是代码

db.listCollections({name: {$ne: 'outlets'}}, {name: {$ne: 'logos'}}).toArray((err, docs) => {
      console.log(docs)
      if (err) {
        return cb(err);
      }

      assert.equal(err, null);

      return cb(null, docs);
    });
  }

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

db.getCollectionNames().filter(name => ['logos','outlets'].indexOf(name) === -1)

也在你的查询中你可以:

db.listCollections({name: {$nin: ['outlets', 'logos']}}).toArray(...)

如果您需要查找汇总(或其他任何内容),您可以这样做:

db.getCollection(YOUR_COLLECTION_NAME).find({})

监督大多数团队MongoDB 你可以安装Robo 3T(Robomongo),有可能连接到服务器