我希望远程项目只包含空格" "
但我的查询不起作用,任何建议
db[source_collection].update({
'_id': customer._id
}, {
'$pull': {
"records.0.items": {
$regex: /^\s*$/
}
}
});
{
"_id" : "025daee4b9b9ba36ed244bb594313ff9",
"records" : [
{
"items" : [
"7089 "
]
},
{
"items" : [
" ",
"78059"
]
},
{
"items" : [
" ",
"5645 "
]
}
]
}
答案 0 :(得分:0)
db[source_collection].find({"_id":customer._id}).forEach(function(doc){
var arr = doc.records.items;
for(var i; i<arr.length;i++)
{
if(!arr[i].replace(/\s/g, '').length)
arr.splice(i,1);
}
doc.records.items = arr;
db[source_collection].save(doc);
}