如何在React式mongo数据(java)中编写来自mongoshell的查询

vm0i2vca  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(541)

我在mongo shell中有这样一个查询可执行文件:

db.devices.find({_id: {$gt: ObjectId("5fd931e00000000000000000")}})

我想把它写在spring-boot-reactive-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");
}
}
km0tfn4u

km0tfn4u1#

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

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");
}

相关问题