db.getCollection('customerInformation').aggregate(
[
{
$project:
{
item: 1,
yearSubstring: { $substr: [ "$idCardNumber", 16, 1 ] },
}
}
]
).forEach(
function (elem) {
var temp ;
print(elem.id);
temp = {yearSubstring:{$mod:[2,1]}};
print(temp);
}
);
function printNumber(Nubmer){
print(1);
};
db.getCollection('customerInformation').find({}).forEach(
function (elem){
print(elem);
printNumber(elem.idCardNumber);
}
);
db.getCollection('customerInformation').find({}).forEach(
function (elem){
var cardNo=elem.idCardNumber;
cardNo={$substr:[cardNo,17,1]};
var num= cardNo:{$mod:[2,1]};
print(num)
}
);
db.getCollection('customerInformation').find().forEach( function(u) { printjson(u); } );
function printNumber(number){
print(number);
print(number.length);
var temp=number.substr(16,1);
print(temp);
if(parseInt(temp)%2===0)
{
db.getCollection('customerInformation').update({"idCardNumber":number},{$set: {'sex':'女'}});
print("ok");
}
else
{
db.getCollection('customerInformation').update({"idCardNumber":number},{$set: {'sex':'男'}});
print("false");
}
};
db.getCollection('customerInformation').find({}).forEach(
function (elem){
printNumber(elem.idCardNumber);
}
);