使用 Mongo Spring 数据与 Mongo 的控制台(日期)查询日期 [英] Querying dates with Mongo Spring data vs Mongo's console (dates)

查看:59
本文介绍了使用 Mongo Spring 数据与 Mongo 的控制台(日期)查询日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 MongoDB 上使用 Spring Data 查询日期时,序列化的 DBObject 可能类似于 {"start" : { "$lt" : {"$date" : "2012-08-06T16:19:14.044Z"}}},这在 Spring Data 的上下文中是有效的,但是该查询不会在 Mongo 的控制台中带来任何结果.在控制台中,这个确实返回了预期的结果 {"start" : { "$lt" : ISODate("2012-08-06T16:19:14.044Z")}}}.

When querying for a date with Spring Data on MongoDB, the serialized DBObject could look something like {"start" : { "$lt" : {"$date" : "2012-08-06T16:19:14.044Z"}}}, which is valid in the context of Spring Data, but that query brings no results in Mongo's console. In the console this one does return the expected results {"start" : { "$lt" : ISODate("2012-08-06T16:19:14.044Z")}}}.

那么 Spring Data 和 Mongo 控制台中的查询有何不同?谢谢

So what is making queries in Spring Data and Mongo's console different? Thx

推荐答案

您无法在 shell 中从 Spring Data 运行序列化"查询.序列化"查询显示在标准 JSON 中,而不是包含 ISODate() 等的扩展 JSON,并且它与 shell 不兼容.

You can't run the "serialized" query from Spring Data in the shell. The "serialized" query shows up in standard JSON, rather than the extended JSON that contains ISODate(), etc., and it's not compatible with the shell.

http://www.mongodb.org/display/DOCS/Mongo+扩展+JSON

这篇关于使用 Mongo Spring 数据与 Mongo 的控制台(日期)查询日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆