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"
    
       
  }
 ]
5
  • You can try using a regex query. Commented Jun 9, 2021 at 13:35
  • Does this answer your question? Checking if a field contains a string Commented Jun 9, 2021 at 13:36
  • Nope I want to get all the documents that have a comma(inside string)in Process field. Commented Jun 9, 2021 at 14:11
  • its same just use string whatever you want to search in field, { Process: { $regex: "," } } Commented Jun 9, 2021 at 14:21
  • its working @turivishal thanks Commented Jun 9, 2021 at 14:31

1 Answer 1

0

Search in field

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

Query Should be

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

@turivishal thanks for your answer

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.