4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MongoDB - データ型(BSON Type)を確認する方法

Posted at

MongoDBの特定のフィールドのBSON Typeを確認したかったので調べた時のメモ

動作確認環境

  • OS: Ubuntu14.04
  • MongoDB: 3.0.4

BSON Type一覧

Type Number Notes
Double 1
String 2
Object 3
Array 4
Binary data 5
Undefined 6 Deprecated.
Object id 7
Boolean 8
Date 9
Null 10
Regular Expression 11
JavaScript 13
Symbol 14
JavaScript (with scope) 15
32-bit integer 16
Timestamp 17
64-bit integer 18
Min key 255 Query with -1.
Max key 127

確認方法

まずはテストデータ

db.test.save({id:1})
db.test.save({id:NumberLong(1)})
db.test.save({id:"1"})

テストデータ確認

db.test.find()
{ "_id" : ObjectId("55b0a23cb32d11a401f7dd7a"), "id" : 1 }
{ "_id" : ObjectId("55b0a2cfb32d11a401f7dd7d"), "id" : NumberLong(1) }
{ "_id" : ObjectId("55b0a27eb32d11a401f7dd7b"), "id" : "1" }

String Typeの抽出

db.test.find({id:{$type:2}})
{ "_id" : ObjectId("55b0a27eb32d11a401f7dd7b"), "id" : "1" }

64-bit integer Type型の抽出

db.test.find({id:{$type:18}})
{ "_id" : ObjectId("55b0a2cfb32d11a401f7dd7d"), "id" : NumberLong(1) }

参考

http://docs.mongodb.org/manual/reference/bson-types/
http://tm8r.hateblo.jp/entry/20110630/1309364124

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?