查询以找到所有非零毫秒的文档 [英] Query to find all documents with non-zero milliseconds

查看:39
本文介绍了查询以找到所有非零毫秒的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有大量的transaction文档(〜2M)

There is a large collection of transaction documents (~2M)

每个transaction文档都有一个source.billDate字段:

Each transaction document has a source.billDate field:

"source.billDate" : ISODate("2018-07-23T16:02:06.797Z")
// or //
"source.billDate" : ISODate("2018-07-22T14:21:56.000Z")

您会看到一些日期以毫秒为单位,而有些则没有毫秒.

我想知道是否有一种方法可以使用MongoDB查询来查找在billDate日期中具有毫秒数的transaction文档.

I'm wondering if there is a way to use MongoDB query to find transaction documents that have milliseconds in their billDate date.

有可能吗?

推荐答案

您可以在mongodb 3.6 版本中尝试以下查询

You can try below queries in mongodb 3.6 version

您必须首先使用 date中提取毫秒> $dateToParts ,然后您可以轻松地将具有毫秒 $ne 0

You have to first extract millisecond from your date using $dateToParts and then you can easily match with the documents having millisecond $ne 0

db.collection.aggregate([
  { "$match": {
    "$expr": {
      "$ne": [
        { "$millisecond": {
          "date": "$source.billDate",
          "timezone": "America/New_York"
        }},
        0
      ]
    }
  }}
])

或者也可以使用查找查询

Or with find query as well

db.collection.find({
  "$expr": {
    "$ne": [
      { "$millisecond": {
        "date": "$source.billDate",
        "timezone": "America/New_York"
      }},
      0
    ]
  }
})

这篇关于查询以找到所有非零毫秒的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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