Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$facet not working #435

Open
nalnir opened this issue Sep 29, 2020 · 2 comments
Open

$facet not working #435

nalnir opened this issue Sep 29, 2020 · 2 comments

Comments

@nalnir
Copy link

nalnir commented Sep 29, 2020

I'm getting this error trying to use $facet in aggregation pipeline:

{message: "aggregation stage "$facet" is not supported", name: "e", errorCode: 5, errorCodeName: "InvalidParameter", stack: "e: aggregation stage "$facet" is not supported↵   …m/stitch-sdks/js/bundles/4.8.0/stitch.js:1:203137"}

Are you gonna support $facet in the future or is my code incorrect?
Im trying to get a count of all documents after I limited them.

stitchApp.auth.loginWithCredential(new AnonymousCredential()).then((user) => {
                db.collection('products').aggregate([
                    { $facet: {
                        "products": [
                            { $match: query },
                            {
                                $group: {
                                    _id: "$groupid",
                                    id: { $last: "$_id" },
                                    images: { $last: "$images" },
                                    description: { $last: "$description" },
                                    barcode: { $min: "$barcode" },
                                    category: { $last: "$category" },
                                    subcategory: { $last: "$subcategory" }, 
                                    discount: { $last: "$discount" },
                                },
                            },
                            { $sort: { '_id': 1 } },
                            { $limit: 30 }, 
                        ],
                        "totalCount": [
                        { $match: query },
                            {
                                $group: {
                                    _id: "$groupid",
                                    count: { $sum: 1 }
                                },
                            },
                        ]
                    } },
                ]).toArray().then(result=>{
                    ...
                })
})
@drewdipalma
Copy link

Hi – Unfortunately it's very difficult for $facet to work with our permissions so it's not currently supported by the SDKs. However, you can create a Function which runs as System and that uses $facet. You can find more information on aggregation expressions with limited availability here.

@nalnir
Copy link
Author

nalnir commented Oct 12, 2020

Alright, will check the link you sent. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants