1. 程式人生 > >mongodb檢視某個欄位的資料型別

mongodb檢視某個欄位的資料型別

$type操作符

檢測型別
種類 代號 別名
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”
JavaScript 13 “javascript”
Symbol 14 “symbol”
JavaScript (with scope) 15 “javascriptWithScope”
32-bit integer 16 “int”
Timestamp 17 “timestamp”
64-bit integer 18 “long”
Min key -1 “minKey”

Max key 127 “maxKey

檢視“times”該欄位的資料型別:
db.getCollection('content').find({"times":{$type:"long"}})
db.getCollection('content').find({"times":{$type:18}})
更改資料型別
db.getCollection('zl').find({'like' : { $type : 2 }}).forEach(function(x) {
    x.like = parseInt(x.like);
    db.getCollection('zl').save(x);
})