question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

find and findOne query fails with error

See original GitHub issue

Repro steps:

  1. Connect to a database
  2. Open a scrapbook
  3. Type any of the following queries:
    1. db.user.findOne(<key>: <value>)
    2. db.user.find(<key>: <value>)
  4. Execute the MongoDB Command

Expect:

VSCode to display the JSON for the document

Actual:

Action: cosmosDB.executeMongoCommand Error type: Error Error Message: Error near line 0, column 23, text ‘:’. Please check syntax.

Environment:

Version: 0.7.2 OS: darwin Insiders Build

Gush:

I love being able to do database stuff in Code, and it’s one of the several things I brag about to other engineers when trying to convert them 😄

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fiveisprimecommented, Jun 20, 2018

I think you’re just missing some curly braces. Note the error Error near line 0, column 23, text ':'. Please check syntax. the colon is unexpected because the curlies are missing.

db.user.findOne({ <key>: <value> })
db.user.find({ <key>: <value>})

so try db.user.find({ "userId": "6b0ab018-0872-4a19-9698-571a106dd837" })

Find accepts a query object and you’re just passing strings separated by a colon.

0reactions
fiveisprimecommented, Jun 20, 2018

Yay! Glad that solved it. 😄 Thanks for following up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MongoDB Node findone how to handle no results?
The problem is say I dont have any results, err is still null whether I find a result or don't. How would I...
Read more >
If findOne query returns nothing throw an error #3298 - GitHub
There should be a way to define that a query like .findOne should throw and error if there were not documents matching the...
Read more >
db.collection.findOne() — MongoDB Manual
Returns one document that satisfies the specified query criteria on the collection ... Although similar to the find() method, the findOne() method returns...
Read more >
Mongoose v6.8.1: API docs
Mongoose.prototype.CastError(). Parameters. type «String» The name of the type. value «Any» The value that failed to cast.
Read more >
MongoDB findOne Example - DigitalOcean
MongoDB findOne - Empty Query specification ... void emptyFindOne() throws UnknownHostException { // Get a new connection to the db assuming ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found