$facet 是如何工作的?

How does $facet works?

我正在使用 $facet,它在我的 mlab 上运行良好,但是当我连接到 azure cosmos DB 时它说

{"error":{"ok":0,"errmsg":"Unrecognized pipeline stage name: $facet","code":40324,"codeName":"40324","name":"MongoError"}}

我正在使用以下查询



collection.aggregate([{
        $match: "test"
    },
    {
        $facet: {
            metadata: [{
                    $count: "total"
                }

            ],
            data: [{
                    $project: {

                        fieldname: 1,


                    }
                }

            ]

        }
    }

])```

根据下面记录的链接,AZURE 和 AWS 不支持 $facet。

https://docs.microsoft.com/es-es/azure/cosmos-db/mongodb-feature-support-36#aggregation-stages

https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html#w144aac17c19b5b3