如何使用 MongoRepository 通过不存在的 属性 找到一个文档?

How to findOne document by a non existent property with MongoRepository?

我在 MongoDB 集合中有一堆文档。其中很多都没有时间戳属性,我想一一添加。

 private final MongoRepository mongoRepository;

我已经尝试使用 Ouery 来过滤这些文档,但没有得到肯定的答复。

@Query("{'timestamp' : null}")
Document findOneIssueByMissingArchivedTimestamp();

现在我想使用 MongoRepository 的 findOne 函数。我只想找到没有时间戳和 return 其中之一的文档。有人知道怎么做吗?

最后我使用了 Spring 魔法并将这个函数添加到 MongoRepository 中,它完成了工作。感谢您的帮助:)

Optional<Document> findFirstByTimestampIsNull();