简体   繁体   English

如何在 Mongo db 中查询包含具有特定类型的列的行?

[英]How do you query a Mongo db for rows containing a column with a specific type?

I have a collection that has ended up with a column containing an updated timestamp, sometimes as a text field, sometimes as a date field.我有一个以包含更新时间戳的列结束的集合,有时作为文本字段,有时作为日期字段。 I am looking for the syntax to execute a query to find all rows that contain that field as a date type.我正在寻找执行查询的语法,以查找包含该字段作为日期类型的所有行。

在此处输入图像描述

You can use $type with $not您可以将$type$not一起使用

Checking the not scenario.检查not场景。 If type is not of string, then consider that doc.如果类型不是字符串,则考虑该文档。

playground操场

db.collection.find({
  "key": {
    $not: {
      $type: "string"
    }
  }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM