MongoDB 数据类型查询 — $type使用
MongoDB 数据类型查询 — $type使用MongoDB 使用过程中经常需要根据字段的类型来查询数据, 而MongoDB中查询字段类型是通过$type操作符来实现.$type使用法语:db.集合名.find({$type:类型值});//这里的类型值能使用Number也能使用alias举个例子:db.person.find({address:{$type:2}});//查询address字段
·
MongoDB 数据类型查询 — $type使用
MongoDB 使用过程中经常需要根据字段的类型来查询数据, 而MongoDB中查询字段类型是通过$type操作符来实现.
$type使用法语:
db.集合名.find({$type:类型值}); //这里的类型值能使用Number也能使用alias
- 举个例子:
db.person.find({address:{$type:2}}); //查询address字段数据类型为字符串
db.person.find({address:{$type:"string"}}); //查询address字段数据类型为字符串
- 复杂些的
db.person.find({address:null}); //注意,这样查询会将没有 address 列的数据一并查询出来
db.person.find({address:{$exists:true, $eq:null}}); //这样查询的是 address 列值为null 的数据
db.person.find({address:{$type:10}}); //这样查询的是 address 列值为null 的数据
- python 代码
{'number': {'$type': 18}}
$type 有效的类型值,如下:
| Number | Alias | Type |
|---|---|---|
| 1 | “double” | Double |
| 2 | “string” | String |
| 3 | “double” | Object |
| 4 | “array” | Array |
| 5 | “binData” | Binary data |
| 6 | “undefined” | Undefined |
| 7 | “objectId” | ObjectId |
| 8 | “bool” | Boolean |
| 9 | “date” | Date |
| 10 | “null” | Null |
| 11 | “regex” | Regular Expression |
| 12 | “dbPointer” | DBPointer |
| 13 | “javascript” | JavaScript |
| 14 | “symbol” | Symbol |
| 15 | “javascriptWithScope” | JavaScript (with scope) |
| 16 | “int” | 32-bit integer |
| 17 | “timestamp” | Timestamp |
| 18 | “long” | 64-bit integer |
| 19 | “decimal” | Decimal128 |
| -1 | “minKey” | Min key |
| 127 | “maxKey” | Max key |
转载于 https://www.cnblogs.com/YWDCB/p/9453887.htm
更多推荐



所有评论(0)