Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worst Logger for #mongoTemplate.find #4860

Open
xjward opened this issue Dec 20, 2024 · 1 comment
Open

Worst Logger for #mongoTemplate.find #4860

xjward opened this issue Dec 20, 2024 · 1 comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: bug A general bug

Comments

@xjward
Copy link

xjward commented Dec 20, 2024

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"}]}

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 20, 2024
@mp911de
Copy link
Member

mp911de commented Jan 13, 2025

Feel free to submit a pull request. It would also make sense to cross-check with the reactive implementation.

@mp911de mp911de added type: bug A general bug status: ideal-for-contribution An issue that a contributor can help us with and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants