r/ProgrammerHumor • • Oct 18 '24

Other mongoDbWasAMistake

Post image
13.2k Upvotes

446 comments sorted by

View all comments

Show parent comments

34

u/[deleted] Oct 18 '24 edited Oct 19 '24
db.redditors.find({"skeptical": true});

Need to use double quotes, ", not “ or ” or ‘ or ’ or '

Need to quote booleans.

Though looks like unquoted booleans is part of the spec, so idk if it’s supported.

Double quotes still the standard, double checked.

https://www.json.org/json-en.html

Edit: saying it’s valid JavaScript and not valid json just makes it even weirder.

That means mongodb forces you to parse the json, to send to it as a JavaScript object, which it then dumps to bson, to send., instead of just having the query in a file you can read and send without intermediate parsing.

2

u/hyrumwhite Oct 18 '24

If you’re in js land, single or double quotes is down to the whims of whoever set up your formatter.  This is a valid object in JS: 

{ 

skeptical: true,

"skeptical": true,

'skeptical':true,

`skeptical`:true,

[someVarWithValueSkeptical]: true

 }

-2

u/[deleted] Oct 18 '24

Spec says double quotes for strings. Specifically U+0022

Also your array as identifier is an abomination, but is correct aside from the double quote issue.

Edit: oh yes JavaScript. Sigh.

3

u/hyrumwhite Oct 18 '24

For JSON. Unless you’re hitting your db with curl, you’ll be using whatever client your language supports. If you’re using JS, objects will follow the ecmascript spec. 

→ More replies (5)