Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
Convert string to query document type in mongodb

I have a string

var queryString = '{Occupation: occupation, Budget: budget , Interestedin: interest, Project: project}'

Where all the names are variable names, I want to pass this string into db.User.find( QUERY ). I have used JSON.parser to parse the same by doing

var object =. JSON.parse(queryString)
var result = await User.find(object)

But still not getting any results. When I try to print JSON.parse output on console, it prints nothing.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

With some initial sanitisation it is working:

 mongos> var queryString = '{ "Occupation": "occupation", "Budget": "budget" , "Interestedin": "interest" , "Project": "project" }'
 mongos> printjson(JSON.parse(queryString))
 {
    "Occupation" : "occupation",
    "Budget" : "budget",
    "Interestedin" : "interest",
    "Project" : "project"
 }
 mongos> 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!