【问题标题】:Search query through all collections in mongodb通过 mongodb 中的所有集合搜索查询
【发布时间】:2022-01-04 19:35:19
【问题描述】:

我正在使用 mongodb Realm 函数,并希望对数据库中的所有集合运行此查询。我必须写一个集合名称;否则,我会收到此错误:

'(AtlasError) Pipeline can only have no collection if the first stage is $changeStream', error_code: 'MongoDBError'

这是我的代码:

exports = function (payload) {
  const movies = context.services
    .get('mongodb-atlas')
    .db('subsDB')
    .collection('subtitles');

  let arg = payload.query.arg;
  let found=movies.aggregate([
    {
      $search: {
        index: 'default',
        text: {
          query: arg,
          path: {
            wildcard: '*',
          },
        },
      },
    },
   
  ]);

如何对数据库中的所有集合运行此查询?

【问题讨论】:

    标签: mongodb mongodb-atlas mongodb-realm mongodb-atlas-search


    【解决方案1】:

    使用db.getCollectionNames:

    db.getCollectionNames().forEach(function(collname) {
        c=db[collname].aggregate(yourPipeline);
    });
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-06
      • 2020-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 2014-02-15
      相关资源
      最近更新 更多