我正在尝试将类型字符串更改为整数。以下代码在简单搜索时选择正确的元素,并且该代码非常适合顶部的字符串元素。
db.providers.find({'assignments.assignment' :
{$elemMatch :
{
as_total_hours :
{$exists : true}}}}).forEach( function(obj) {
obj.as_total_hours = parseInt(obj.as_total_hours);
db.providers.save(obj);
})
这是该文档的示例。
"dev_active_interviews" : 0,
"assignments" : {
"assignment" : [
{
"as_rate" : "$3.89",
"as_from" : "05/2011",
"as_to" : "Present",
"as_total_hours " : "16"
},
{
"as_rate" : "$2.22",
"as_from" : "11/2010",
"as_to" : "Past",
"as_total_hours" : "200"
}
]
}