我正在使用mongodb领域函数,并希望对数据库中的所有集合运行此查询。我必须写一个集合名;否则,我会得到这个错误:
'(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: '*',
},
},
},
},
]);如何对数据库中的所有集合运行此查询?
发布于 2021-11-27 00:09:09
使用db.getCollectionNames
db.getCollectionNames().forEach(function(collname) {
c=db[collname].aggregate(yourPipeline);
});https://stackoverflow.com/questions/70129512
复制相似问题