-
Notifications
You must be signed in to change notification settings - Fork 18
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
Unable to create arrays in "$group"-aggregation #24
Comments
That error indicates that its trying, and failing, to automatically figure out what the types of your output fields are, that's the "Schema Inference Failed", but the second part, which is what caused it to fail, seems to be coming from mongo itself. My first recommendation is to disable the schema inference in the query options and explicitly specify the field names and types to expect, and if that works, then it would be very helpful if you could provide a handful (5ish) documents that demonstrate the problem, and I can try to debug. If disabling schema inference also produces an error that has that |
Thank you for the swift reply! To be totally honest, I kind of glanced over "Infer Schema" because it just worked for my other Grafana panels. I'm using the following aggregation-query to create a Table-panel (only for testing). All my observations result from this test db-collection
As expected, this doesn't result in an immediate error. I can specify
Does this maybe don't work in general? I mean, you wrote in the info-box for |
I've managed to reproduce the issue with a test, and I believe I have a fix, I will try to have it implemented and released sometime this week. |
v0.2.0+rc4 is now available, which should resolve this issue. |
Thanks a lot! |
Hello! I think I've just run in similar issue in v0.2.0+rc4 Following group operation works fine: {
"$group": {
"_id": "$_id",
"roundedTimestamp": "$roundedTimestamp",
"averageDuration": { "$avg": "$duration" }
}
}, But when I change {
"$group": {
"_id": {
"$concat": [
{"$toString": "_id"}
]
},
"roundedTimestamp": "$roundedTimestamp",
"averageDuration": { "$avg": "$duration" }
}
}, |
After digging into I suggest that we add switch like "use variables" in |
First of all: Thank you for the plugin, for the majority of my applications it is working flawlessly!
But with one query, I'm stuck.
I've spent the last few hours trying to find the error on my side, so maybe this is a general issue with this plugin.
I'm working with a db-collection whose documents have the following (relevant part) format:
My (intermediate) goal is to group the docs by their name and create an array in each group with the following format:
[{"state": "$statusActivity, "date": "$timestamp}]
My aggregation-query for this looks the following:
I do some
$match
for time range etc. beforehand and a lot of "post-processing" afterward, but this is the critical part which doesn't work.I always get the following error:
Schema Inference Failed: WriteArray can only write a Array while positioned on a Element or Value but is positioned on a TopLevel
I've tried countless versions of my query with
$push
,$addToSet
and even$accumulator
. Also creating empty arrays beforehand, adding the arrays afterward with a second$group
etc. Always the same error message.My queries work flawlessly on mongoplayground.net (I've linked the playground with my test query) and also in the exact db I use with Grafana when I test the query in MongoDB-Express.
Is this a bug/shortcoming of the plugin? Or am I missing something obvious?
The text was updated successfully, but these errors were encountered: