You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法从MongoDB中检索NumberLong类型数据的问题求助

MongoDB查询语句错误分析及修正方案

你的查询语句不正确,无法匹配数据的原因是:在MongoDB Shell环境中,不能用{"$numberLong": "1671979860000"}这种文档格式来表示NumberLong类型的值,这种写法属于MongoDB Extended JSON格式,仅适用于数据导入导出等特定场景,不适合直接用于Shell查询。

正确的查询写法有两种:

  • 方式一:使用NumberLong()函数构造类型匹配的数值
db.getCollection('Emp_Data').find({"updatedDateTime": {"$gte": NumberLong("1671979860000")}});
  • 方式二:直接传入数字(注意:若数值超出JavaScript Number的精度范围(大于2^53),优先用NumberLong避免精度丢失)
db.getCollection('Emp_Data').find({"updatedDateTime": {"$gte": 1671979860000}});

修正后,数据库中updatedDateTime为NumberLong(1672059880000)的记录会被匹配到,因为该值大于查询条件中的1671979860000。

内容的提问来源于stack exchange,提问作者Harish L

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 11:25:21