Mongo shell 函数详解 - 数据类型
> db.language.find({status:1})
{ "_id" : 1, "name" : "java", "status" : 1, "tags" : [ "jsp", "servlet", "groovy" ] }
{ "_id" : 2, "name" : "db", "status" : 1, "tags" : [ "mysql", "mongo" ] }
{ "_id" : 3, "name" : ".net", "status" : 1, "tags" : [ "asp" ] }
{ "_id" : 5, "name" : "ruby", "status" : NumberLong(1) }
{ "_id" : 4, "name" : "javascript", "status" : 1, "tags" : [ ] }
>
> db.language.find({status:{$type:1}})
{ "_id" : 4, "name" : "javascript", "status" : 1, "tags" : [ ] }
>
> db.language.find({status:{$type:16}})
{ "_id" : 1, "name" : "java", "status" : 1, "tags" : [ "jsp", "servlet", "groovy" ] }
{ "_id" : 2, "name" : "db", "status" : 1, "tags" : [ "mysql", "mongo" ] }
{ "_id" : 3, "name" : ".net", "status" : 1, "tags" : [ "asp" ] }
>
> db.language.find({status:{$type:18}})
{ "_id" : 5, "name" : "ruby", "status" : NumberLong(1) }
>
> db.language.find({"name":{$type:2}})
{ "_id" : 1, "name" : "java", "status" : 1, "tags" : [ "jsp", "servlet", "groovy" ] }
{ "_id" : 2, "name" : "db", "status" : 1, "tags" : [ "mysql", "mongo" ] }
{ "_id" : 3, "name" : ".net", "status" : 1, "tags" : [ "asp" ] }
{ "_id" : 5, "name" : "ruby", "status" : NumberLong(1) }
{ "_id" : 4, "name" : "javascript", "status" : 1, "tags" : [ ] }
>
> db.language.update({},{$set:{status:NumberInt(1)}},false,true)
> db.language.find({status:{$type:1}})
> db.language.find({status:{$type:16}})
{ "_id" : 1, "name" : "java", "status" : 1, "tags" : [ "jsp", "servlet", "groovy" ] }
{ "_id" : 2, "name" : "db", "status" : 1, "tags" : [ "mysql", "mongo" ] }
{ "_id" : 3, "name" : ".net", "status" : 1, "tags" : [ "asp" ] }
{ "_id" : 5, "name" : "ruby", "status" : 1 }
{ "_id" : 4, "name" : "javascript", "status" : 1, "tags" : [ ] }
> db.language.find({status:{$type:18}})
>
命令行下数字会被转成Double类型,如果需要整型,使用NumberLong或NumberInt
mongo官方介绍
http://docs.mongodb.org/manual/reference/operator/query/type/
上一篇: Linux服务器上用iScanner删除网页恶意代码的方法
下一篇: css网页切图实例教程