Mongo Java - 列出所有包含电话号码或信用卡号或邮政编码数据的文档,当我们不知道字段名称时



您能否在Mongo Java中建议一个选项,以查找所有具有电话号码或信用卡号或邮政编码数据的文档,当我们不知道字段名称时。

我试过这个,但这根本不起作用。

AggregateIterable<Document> output = collection.aggregate(
Arrays.asList(
new Document(
"$project", new Document(
"x", new Document(
"$objectToArray", "$$CURRENT"
)
)
),
new Document("$unwind", "$x"),
new Document(
"$match", new Document(
"x.k", new Document(
"$in", new BasicDBObject("$regex", "^(ISBN(-10)?:? )?([-0-9xX ]{13}|[0-9X]{10})$")
)
)
)
)
); 
For example Input
{ 
"_id" : ObjectId("5a0bf2604510c319181df436"), 
"name" : "Oneindb2", 
"number" : 11, 
"phonenumber" : 111111
}
{ 
"_id" : ObjectId("5a0bf2604510c319181df437"), 
"dname" : "creditCardtwoindb2",   
"zipc" : "5670228"
}
{ 
"_id" : ObjectId("5a0bf2604510c319181df439"), 
"name" : "creditCardfourindb2", 
"CHECKnumber" : 56, 
"checkISO" : "second_iso"
}
{ 
"_id" : ObjectId("5a0bf2604510c319181df43a"), 
"name" : "creditCardfiveindb2", 
"ddnumber" : 56, 
"ISOS" : "second_iso"
}
{ 
"_id" : ObjectId("5a0bf2604510c319181df438"), 
"cname" : " 57656yuio89789"
"personnumber" : 33, 
"NISO" : "three_iso"
}

*Expected output is*
{ 
"_id" : ObjectId("5a0bf2604510c319181df436"), 
"name" : "Oneindb2", 
"number" : 11, 
"pnumber" : 111111
}
{ 
"_id" : ObjectId("5a0bf2604510c319181df437"), 
"dname" : "creditCardtwoindb2",   
"zipc" : "5670228"
}
{ 
"_id" : ObjectId("5a0bf2604510c319181df438"), 
"cname" : " 57656yuio89789"
"number" : NumberInt(33), 
"ISO11" : "three_iso"
}
because these documents fields (at least one field) has either phone number or credit card number or zip code
Note: field names are not same in all the documents it may vary.

相关内容

最新更新