db.foo.find();
_id | type
-------------
10001 1
10002 'a'
10003 [1, 2, 3, 4]
As you know, the $type will match the type code in mongo query, like this:
db.foo.find({type: {$type: 4}});
_id | type
----------
10003, [1, 2, 3, 4]
and then, I write a javascript shell script called test.js
var curs = db.foo.find();
curs.forEach(showTypeCode);
function showTypeCode(cur) {
print(cur.type + '-' + typeof(cur.type));
};
results:
1-number
a-string
1,2,3,4-object (this is an array, it's 4 in mongo)
here is my question, how can I get the array type code in the mongo shell