gpt4 book ai didi

mongodb - MongoRepository JSON 日期查询 (Spring)

转载 作者:行者123 更新时间:2023-12-02 03:51:17 25 4
gpt4 key购买 nike

我正在尝试使用自己的查询来查询 mongo 存储库:

@Repository
public interface LogEntryRepository extends MongoRepository<LogEntry,String> {

@Query("{'created_at' : {{ $gte: ISODate(?0)},{$lt: ISODate(?1)}}, " +
"$or: [{'site': {$regex: ?2}}, {'login': {$regex: ?2}}, {'ip': {$regex: ?2}} ]" +
"}")
public Page<LogEntry> findByDateTimeBetweenAndCriteria(String isoStartDate, String isoEndDate, String searchTerm, Pageable page);

}

我想要实现的是使用关键字搜索过时的日志。上面提示解析错误:

        Caused by: com.mongodb.util.JSONParseException: 
{'created_at' : { $gte: ISODate("_param_0"), $lt: ISODate("_param_1")}, $or: [{'site': {$regex: "_param_2"}}, {'login': {$regex: "_param_2"}}, {'ip': {$regex: "_param_2"}} ]}
^

如果我将 ISODate(?0) 替换为简单的 ?0,它会生成 第 1 页(共 0 页),其中包含未知实例

字符串 isoStartDateisoEndDatejava.util.Date 生成,看起来像这样 2017-06-27T00: 00:00.000Z

我如何在那里找到我的约会对象?

最佳答案

ISODate 是一个 Mongo shell 构造,用于创建 BSON 日期,并且绝对不是有效的 JSON,我相信这就是您的错误所提示的。

尝试将上述 ISODate 调用替换为 { '$date' : '?0' }{ '$date' : '?1' } 中的建议这个answer 。所有字符串可能都需要用单引号引起来。

关于mongodb - MongoRepository JSON 日期查询 (Spring),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45338505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com