有关投影和子文档的Spring Data Mogo问题

时间:2018-08-03 08:34:10

标签: spring-data-mongodb

嗨,我有一个查询在robo3T中运行得很好:

    db.getCollection('meetingComplete').aggregate([
   { "$match" : {
        "prices.errors": { "$elemMatch": { "$exists": true } } 
     }
   },   
   { "$unwind" : "$prices" },
   { "$match" : {
       "prices.errors.0" : { "$exists" : true}
     }
   },
   { "$project" : {

       "prices.errors" : 1 ,
       "number" : 1,
       "askedDate" : 1,
       "name" : 1,
       "date" : 1,
     }
   },
])

我只得到 prices.errors 子文档,删除了所有其他 prices。 * 字段。最终结果。

现在对Spring Data Mongo做同样的事情:

List<Meeting> mappedResults = mongoTemplate.aggregate(newAggregation(Meeting.class,
                match(where("prices.errors.0").exists(true)),
                unwind("prices"),
                match(where("prices.errors.0").exists(true)),
                group("date", "name")
                        .addToSet("prices.errors").as("prices.errors")
                        .addToSet("number").as("number")
                        .addToSet("askedDate").as("askedDate")
                        .addToSet("name").as("name")
                        .addToSet("date").as("date"),
                project("prices.errors", "number", "askedDate", "name", "date"),
                skip(new Long(pageable.getPageNumber() * pageable.getPageSize())),
                limit(pageable.getPageSize())
        ), Meeting.class).getMappedResults();

但是我遇到了这个错误:

org.springframework.data.mongodb.UncategorizedMongoDbException:  Command failed with error 40235: 'The field name 'prices.errors' cannot contain '.'' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "The field name 'prices.errors' cannot contain '.'", "code" : 40235, "codeName" : "Location40235" }; nested exception is com.mongodb.MongoCommandException: Command failed with error 40235: 'The field name 'prices.errors' cannot contain '.'' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "The field name 'prices.errors' cannot contain '.'", "code" : 40235, "codeName" : "Location40235" }

那么,有什么想法为什么spring数据mongo canot的行为与查询相同?

谢谢

0 个答案:

没有答案