MongoDB 数据类型查询——$type使用

在MongoDB中根据字段的数量类型来查询数据使用$type操作符来实现,具体使用法语:

1
db.集合名. find ({$ type :类型值})     // 这里的类型值能使用Number也能使用 alias

举个例子:

1
2
db.person. find ({address:{$ type :2}})          // 查询address字段数据类型为字符串
db.person. find ({address:{$ type : "string" }})   // 查询address字段数据类型为字符串


$type 有效的类型值,如下:

Type Number Alias Notes
Double 1 “double”
String 2 “string”
Object 3 “object”
Array 4 “array”
Binary data 5 “binData”
Undefined 6 “undefined” Deprecated.
ObjectId 7 “objectId”
Boolean 8 “bool”
Date 9 “date”
Null 10 “null”
Regular Expression 11 “regex”
DBPointer 12 “dbPointer” Deprecated.
JavaScript 13 “javascript”
Symbol 14 “symbol” Deprecated.
JavaScript (with scope) 15 “javascriptWithScope”
32-bit integer 16 “int”
Timestamp 17 “timestamp”
64-bit integer 18 “long”
Decimal128 19 “decimal” New in version 3.4.
Min key -1 “minKey”
Max key 127 “maxKey”  


官网参考:https://docs.mongodb.com/manual/reference/operator/query/type/index.html

原文转自: http://www.xuexiyuan.cn/article/detail/107.html


猜你喜欢

转载自blog.csdn.net/user_longling/article/details/80565981
今日推荐