我想确定 MongoDB 中 JSON 文档中字段的数据类型。可以这样做吗?例如,如果我有
{
"created_at": "Fri Aug 04 05:42:03 +0000 2017",
"id": 893346273255866400,
"id_str": "893346273255866368"
}
我想知道“created_at”接受什么类型的值,以便我可以在 MongoDB 中制定查询
最佳答案
您可以使用 typeof 运算符返回 MongoDB 中值的类型,也可以在查询中使用 $type 运算符按特定类型进行查询。 例如
db.inventory.find( { price: { $type: "decimal" } } )
有关更多信息,请参阅 https://docs.mongodb.com/manual/core/shell-types/#check-types-in-shell
关于javascript - 如何确定 JSON 中字段的数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48367508/