MongoDB $ type Operator
Description
The $ type operator is based on the BSON type to retrieve matching data types in the set and return results.
The following table lists the types that MongoDB can use:
Type |
Number |
Remarks |
Double |
1 |
|
String |
2 |
|
Object |
3 |
|
Array |
4 |
|
Binary data |
5 |
|
Undefined |
6 |
Abandoned. |
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-1. |
Max key |
127 |
|
The database name we use is "runoob", and the Set name is "col". The following figure shows the data we inserted.
Simple set "col ":
> Db. col. insert ({title: 'php ', description: 'php is a powerful server-side scripting language for creating dynamic interactive sites. ', By: 'cainiao tutorial', url: 'http: // www.runoob.com ', tags: ['php'], likes: 200 })
> Db. col. insert ({title: 'java tutorial ', description: 'java is an advanced programming language launched by Sun Microsystems in May 1995. ', By: 'cainiao tutorial', url: 'http: // www.runoob.com ', tags: ['java'], likes: 150 })
> Db. col. insert ({title: 'mongodb ', description: 'mongodb is a Nosql database', by: 'cainiao ', url: 'http: // www.runoob.com ', tags: ['mongodb '], likes: 100 })
Run the find () command to view the data:
> Db. col. find () {"_ id": ObjectId ("56066542ade2f21f36b0313a"), "title": "PHP tutorial", "description ": "PHP is a powerful server-side scripting language for creating dynamic interactive sites. "," By ":" cainiao tutorial "," url ":" http://www.runoob.com "," tags ": [" php "]," likes ": 200} {"_ id": ObjectId ("56066549ade2f21f36b0313b"), "title": "Java tutorial", "description ": "Java is a high-level programming language launched by Sun Microsystems in May 1995. "," By ":" cainiao tutorial "," url ":" http://www.runoob.com "," tags ": [" java "]," likes ": 150} {"_ id": ObjectId ("5606654fade2f21f36b0313c"), "title": "MongoDB tutorial", "description": "MongoDB is a Nosql Database", "": "cainiao tutorial", "url": "http://www.runoob.com", "tags": ["mongodb"], "likes": 100}
MongoDB operator-$ type instance
To obtain data whose title is String in the "col" set, run the following command:
db.col.find({"title" : {$type : 2}})
Output result:
{"_ Id": ObjectId ("56066542ade2f21f36b0313a"), "title": "PHP tutorial", "description ": "PHP is a powerful server-side scripting language for creating dynamic interactive sites. "," By ":" cainiao tutorial "," url ":" http://www.runoob.com "," tags ": [" php "]," likes ": 200} {"_ id": ObjectId ("56066549ade2f21f36b0313b"), "title": "Java tutorial", "description ": "Java is a high-level programming language launched by Sun Microsystems in May 1995. "," By ":" cainiao tutorial "," url ":" http://www.runoob.com "," tags ": [" java "]," likes ": 150} {"_ id": ObjectId ("5606654fade2f21f36b0313c"), "title": "MongoDB tutorial", "description": "MongoDB is a Nosql Database", "": "cainiao tutorial", "url": "http://www.runoob.com", "tags": ["mongodb"], "likes": 100}
For more MongoDB tutorials, see the following:
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: