gpt4 book ai didi

javascript - MongoDB 计数未返回正确的数字

转载 作者:行者123 更新时间:2023-11-28 03:27:43 25 4
gpt4 key购买 nike

我的时间戳属性是一个数字(日期纪元时间戳)。

给出以下查询:

//q1
db.measurements
.count()

//q2
db.measurements
.find({$or: [
{ timestamp: { $exists: false } },
{ timestamp: null }
]})
.count();

//q3
db.measurements
.find({ timestamp: { $gte: new Date(2019, 9, 18).getTime() } })
.count()

//q4
db.measurements
.find({timestamp: { $not: { $gte: new Date(2019, 9, 18).getTime() } } })
.count()

结果:

  • q1:2492699
  • q2:0
  • q3:2468987
  • q4:6

请解释一下为什么我找不到丢失的 23000 条记录。count() 是否被缓存或者我的索引有问题?也许我的查询是错误的。

最佳答案

尝试这些查询,然后检查结果是否相同。

db.measurements.count()

db.measurements.find({}).count()

db.measurements.find({ timestamp: { $exists: true } }).count();

关于javascript - MongoDB 计数未返回正确的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58486320/

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