0

我正在使用 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: '*',
          },
        },
      },
    },
   
  ]);

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

4

1 回答 1

0

使用db.getCollectionNames

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

于 2021-11-27T00:09:08.693 回答