its me
its me

Reputation: 542

Get comma exist document using mongodb query?

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

Answers (1)

its me
its me

Reputation: 542

Search in field

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

Query Should be

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

@turivishal thanks for your answer

Upvotes: 0

Related Questions