蒙戈文件:春数据蒙戈模板 - 计数的数组
{
"_id" : "1",
"array" : [
{
"item" : "item"
},
{
"item" : "item"
}
]
}
我mongo shell query
看起来像这样:
db.getCollection('collectionName').aggregate(
{$match: { _id: "1"}},
{$project: { count: { $size:"$array" }}}
)
有反正这个用Mongo Template from Spring
实施?
到目前为止,我有这样的:
MatchOperation match = new MatchOperation(Criteria.where("_id").is("1"));
ProjectionOperation project = new ProjectionOperation();
Aggregation aggregate = Aggregation.newAggregation(match, project);
mongoTemplate.aggregate(aggregate, collectionName, Integer.class);
我想我唯一缺少的project
逻辑,但我不知道是否有可能做$size or equivalent
这里。
这其中,'现在是Criteria.where(...) – dragonalvaro