删除mongodb中没有@的文档

时间:2017-05-18 14:09:18

标签: mongodb email

我创建了一个mongodb,并在我填写我的客户端电子邮件地址和相关帐户。但我发现列为电子邮件的某些值根本不是电子邮件。请参阅以下示例。

mydict2 = {}
for key, value in mydict.items():
    mydict2[key] = [value]

myDF = pd.DataFrame.from_dict(mydict2, orient='index'). \
    reset_index(). \
    rename(columns={'index': 'key', 0: 'value'})
myDF['key_count'] = myDF.key.str.len()
myDF['value_count'] = myDF.value.str.len() / myDF.key_count

我想检查密钥{ "_id" : ObjectId("591d9cf30ef9acde11d7af6b"), "email" : "w@Yahoo.com", "src" : [ { "acc" : "yahoo", "name" : "matter" } ] } { "_id" : ObjectId("591daa540ef9acde11d7af6c"), "email" : "122", "src" : [ { "acc" : "ldd" } ] } 是否具有正确的电子邮件值。如果没有,那么我想删除该文件并使我的mongo清洁 我怎么能做到这一点?

1 个答案:

答案 0 :(得分:2)

使用带有$not运算符

的正则表达式的remove命令

db.getCollection('somecollection').remove( { email: { $not: /@/ } } )

我不能100%确定正则表达式能够像这样使用@正常工作。但我建议首先使用find代替remove进行测试。

db.getCollection('somecollection').find( { email: { $not: /@/ } } )