如何在反应性 mongo 数据 (java) 中编写来自 mongoshell 的查询

How to write query from mongoshell in reactive mongo data (java)

我在 mongo shell:

中有这样一个查询可执行文件
db.devices.find({_id: {$gt: ObjectId("5fd931e00000000000000000")}})

我想把它写在 spring 启动反应 mongo 数据中,我的尝试看起来像这样没有成功:

   @Service
public class MongoService {
@Autowired
private final ReactiveMongoTemplate mongo;

public MongoService(ReactiveMongoTemplate mongo) {
    this.mongo = mongo;
}

public Flux<Device> getObjectsByTimestamp(String timestamp) {
    Query query = new Query(Criteria.where("_id").gt("5fd931e00000000000000000"));
    return mongo.find(query, Device.class, "devices");
}
}

能够通过以下方式解决问题:

    public Flux<Device> getObjectsByTimestamp(String timestamp) {
    ObjectId objectId = new ObjectId("5fd931e00000000000000000");
    Query query = new Query(Criteria.where("_id").gt(objectId));
    return mongo.find(query, Device.class, "devices");
}