db.foo.find();
_id | type
-------------
10001 1
10002 'a'
10003 [1, 2, 3, 4]
如你所知,在$型将匹配蒙戈查询类型代码,就像这样:得到JS脚本MongoDB的数据类型
db.foo.find({type: {$type: 4}});
_id |键入
----------
10003,[1,2,3,4]
然后,我写称为一个javascript外壳脚本test.js
var curs = db.foo.find();
curs.forEach(showTypeCode);
function showTypeCode(cur) {
print(cur.type + '-' + typeof(cur.type));
};
结果:
1-number
a-string
1,2,3,4-object (this is an array, it's 4 in mongo)
这里是我的问题,我怎样才能在蒙戈数组类型代码外壳
这是一个已知的bug,MongoDB实际上将一个数组作为一个对象读取。 – Sammaye
这里是它的JIRA:https://jira.mongodb.org/browse/SERVER-1475 – Sammaye
@ Sammaye,我不应该使用这个演示,在javascript []和{}都是对象类型。我想要得到mongo数据类型4.是否有任何方法可以显示这种类型的代码?:) – sashimi