Reputation: 542
User collection below
[
{
"_id" : ObjectId("59a6b381c13a090c70fc21b6"),
"Name":"ABC"
"processNumber" : "FEE 082517",
"Process":"abc,cde"
},
{
"_id" : ObjectId("59a6b381c13a090c70fc21b6"),
"Name":"ABC"
"processNumber" : "FEE 082517",
"Process":"efg"
},
{
"_id" : ObjectId("59a6b381c13a090c70fc21b6"),
"Name":"ABC"
"processNumber" : "FEE 082517",
"Process":"123,3de"
}
]
I have a user collection. I have to prepare a query to check the Process field whether it has any comma in value if it's there we have to return those documents
Expected output :
[
{
"_id" : ObjectId("59a6b381c13a090c70fc21b6"),
"Name":"ABC"
"processNumber" : "FEE 082517",
"Process":"abc,cde"
},
{
"_id" : ObjectId("59a6b381c13a090c70fc21b6"),
"Name":"ABC"
"processNumber" : "FEE 082517",
"Process":"123,3de"
}
]
Upvotes: 1
Views: 572
Reputation: 542
Search in field
{ Process: { $regex: "," } }
Query Should be
db.collection.find({ 'fieldname': { $regex: "," } })
@turivishal thanks for your answer
Upvotes: 0