Answer the question
In order to leave comments, you need to log in
How to delete documents by field?
Hello, such a question arose, I began to familiarize myself with the node js express + mongodb technology stack (I exclude mongoose for now, I say right away to exclude questions about it).
There is a users database, it contains the user collection, it contains documents with the following fields:
{
"_id" : ObjectId("5d8342f4b172fcb285fc597a"),
"name" : "Andrey",
"age" : 32,
"sex" : {
"male" : true,
"female" : false
}
},
{
"_id" : ObjectId("5d834329b172fcb285fc597c"),
"name" : "Anna",
"age" : 48,
"sex" : {
"male" : false,
"female" : true
}
},
{
"_id" : ObjectId("5d8369c1b172fcb285fc597e"),
"name" : "Anna",
"age" : 48,
"postIndex" : 67890
},
{
"_id" : ObjectId("5d8369d4b172fcb285fc597f"),
"name" : "Andrey",
"age" : 48,
"postIndex" : 123456
},
{
"_id" : ObjectId("5d836bb2b172fcb285fc5980"),
"name" : "Anton",
"age" : 48,
"postIndex" : "123456"
},
{
"_id" : ObjectId("5d836c52b172fcb285fc5981"),
"name" : "Annete",
"age" : 48,
"postIndex" : -1975
},
{
"_id" : ObjectId("5d836e91b172fcb285fc5982"),
"name" : "Annete",
"age" : 48,
"postIndex" : 0.0016502834182392193
},
{
"_id" : ObjectId("5d836ec6b172fcb285fc5983"),
"name" : "Annete",
"age" : 48,
"postIndex" : ISODate("2019-09-19T12:04:22.380Z")
}
db.user.remove($where:"/[0-9]+/.test(this.postIndex)")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question