1

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"
    
       
  }
 ]
its me
  • 524
  • 6
  • 28
  • 62

1 Answers1

0

Search in field

{ Process: { $regex: "," } }

Query Should be

db.collection.find({ 'fieldname': { $regex: "," } })

@turivishal thanks for your answer

its me
  • 524
  • 6
  • 28
  • 62