gpt4 book ai didi

MongoDB 聚合错误 "each item in the pipeline must be a document"

转载 作者:IT老高 更新时间:2023-10-28 13:30:10 26 4
gpt4 key购买 nike

我有一个如下所示的 MongoDB 聚合:

[
{
"$match": [
{"Created": {"$gte": ISODate("2014-01-10T00:00:00Z")}}
]
},
{
"$group":
{
"_id": [
{"year": {"$year": "Created"}},
{"month": {"$month": "Created"}},
{"day": {"$dayOfMonth": "Created"}}
],
"count": {"$sum": 1}
}
}
]

当我在 MongoVUE 中运行此查询时,它返回以下错误:

Incorrect syntax in pipelineEach item in the pipeline must be a documentType: System.ExceptionStack:    at MangoUI.ComAggregate.kRemove_Click(Object sender, EventArgs e)

I'm completely stumped, and from my Googling so is the rest of the Intenet-at-large. The query worked correctly before I added the date created $match operator. It's possible that the error belongs to MongoVUE and not MongoDB itself.

The relevant portion of the schema looks like this:

{
"_id" : new BinData(3, "m13wFpp9gUi09cRCuG43aw=="),
"Created" : ISODate("2013-12-19T01:00:20.972Z")
}

谁能帮我找出这个错误的原因?恐怕我完全被难住了。


我不允许回答自己的问题(因为如果您的 StackOverflow 声誉太低,显然在 8 小时内完全不可能自己找到答案?嗯?)所以我在下面发布了答案:

好的,我找到了答案,据我所知,这确实是 MongoVUE 中的一个错误(或至少是一个遗漏和误导性错误消息)。以这种方式编写相同的查询(带有 orid 的修改)是可行的:

{
"$match": {
"Created": {
"$gte": ISODate("2014-01-10T00:00:00Z")
}
}
},
{
"$group": {
"_id": {
"year": {
"$year": "$Created"
},
"month": {
"$month": "$Created"
},
"day": {
"$dayOfMonth": "$Created"
}
},
"count": {
"$sum": 1
}
}
}

(请注意,我真正所做的唯一更改是删除了它周围的数组标记。)

此外,当您在 MongoVUE 中的数组中放置具有多个操作的聚合时,任何都会出现该错误。如果您不使用数组,则操作可以正常工作。如果你添加它,你会突然得到“管道中的每个项目都必须是一个文档。”

最佳答案

pipeline = [{
"$match": {
"Created": {
"$gte": ISODate("2014-01-10T00:00:00Z")
}
}
},
{
"$group": {
"_id": {
"year": {
"$year": "$Created"
},
"month": {
"$month": "$Created"
},
"day": {
"$dayOfMonth": "$Created"
}
},
"count": {
"$sum": 1
}
}
}]

Document.objects.aggregate(*pipeline)

关于MongoDB 聚合错误 "each item in the pipeline must be a document",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21100256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com