Skip to content

Worst Logger for #mongoTemplate.find #4860

Closed
@xjward

Description

@xjward

debug code, :

Query query=Query.query(new Criteria().orOperator(
        Criteria.where("sendUserCode").is("aa"),Criteria.where("sendUserCode").is("bb")
));
query.with(Sort.by(Sort.Order.desc("sendTime")));
final List<CoEntity> coList = mongoTemplate.find(query,CoEntity.class);

debug step in main branches : MongoTemplate#find

protected <S, T> List<T> doFind(String collectionName,
	CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query, Document fields,
	Class<S> entityClass, @Nullable CursorPreparer preparer, DocumentCallback<T> objectCallback) {

MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);

QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
Document mappedFields = queryContext.getMappedFields(entity, EntityProjection.nonProjecting(entityClass));
Document mappedQuery = queryContext.getMappedQuery(entity);

if (LOGGER.isDebugEnabled()) {

	Document mappedSort = getMappedSortObject(query, entityClass);
	LOGGER.debug(String.format("find using query: %s fields: %s sort: %s for class: %s in collection: %s",
			serializeToJsonSafely(mappedQuery), mappedFields, serializeToJsonSafely(mappedSort), entityClass,
			collectionName));
}

return executeFindMultiInternal(new FindCallback(collectionPreparer, mappedQuery, mappedFields, null),
		preparer != null ? preparer : CursorPreparer.NO_OP_PREPARER, objectCallback, collectionName);
}

focus code:

Document mappedSort = getMappedSortObject(query, entityClass);
serializeToJsonSafely(mappedSort)

expect
sort: { "sendTime" : -1}
but
sort: { "$or" : [{ "sendUserCode" : "aa"}, { "sendUserCode" : "bb"}]}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions