-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed as not planned
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.comstatus: invalidAn issue that we don't feel is validAn issue that we don't feel is valid
Description
the mongo source code:
public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware, EnvironmentCapable {
protected <S> S readDocument(ConversionContext context, Bson bson, TypeInformation<? extends S> typeHint) {
Document var10000;
if (bson instanceof BasicDBObject dbObject) {
var10000 = new Document(dbObject);
} else {
var10000 = (Document)bson;
}
Document document = var10000;
TypeInformation<? extends S> typeToRead = this.getTypeMapper().readType(document, typeHint);
Class<? extends S> rawType = typeToRead.getType();
if (this.conversions.hasCustomReadTarget(bson.getClass(), rawType)) {
return this.doConvert(bson, rawType, typeHint.getType());
} else if (Document.class.isAssignableFrom(rawType)) {
return bson;
} else if (DBObject.class.isAssignableFrom(rawType)) {
if (bson instanceof DBObject) {
return bson;
} else if (bson instanceof Document) {
Document doc = (Document)bson;
return new BasicDBObject(doc);
} else {
return bson;
}
} else if (typeToRead.isMap()) {
return context.convert(bson, typeToRead);
} else if (BSON.isAssignableFrom(typeHint)) {
return bson;
} else {
public class AggregationResults<T> implements Iterable<T> {
private final List<T> mappedResults;
private final Document rawResults;
@Nullable
private final String serverUsed;
}
i have saw the mongo code have go to else branch. but rawResults is normal, and mappedResults is bad. I Don't know why?
i suspect that something wrong with MappingMongoConverter
@Test
void testAggregate() {
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("programming_language").is("Perl")),
Aggregation.lookup("commits", "hash", "hash", "commits"),
Aggregation.lookup("fixes", "commits.hash", "hash", "fixes"),
Aggregation.lookup("cve", "fixes.cve_id", "cve_id", "cves"),
Aggregation.unwind("cves")
);
// 执行聚合操作并返回结果
List<Cve> cves = mongoTemplate.aggregate(aggregation, "file_change", Cve.class).getMappedResults();
System.out.println();
}
// =========
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document("cve")
public class Cve {
@Id
private ObjectId id;
@Field("cve_id")
private String cveId;
@Field("published_date")
private String publishedDate;
...
}
Metadata
Metadata
Assignees
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.comstatus: invalidAn issue that we don't feel is validAn issue that we don't feel is valid