MongoDB query equivalent in SQL

I am relatively new to MongoDb as well as RDBMS.

I understand that, in SQL, even though I don’t have data for the field, the field will be available. Whereas in MongoDB if the data is not there, the field won’t be there.

Out of curiosity, is there a SQL Query Equivalent to the below MongoDb query?

db.goods.find({“product” :{ $exists : true }});

Welcome to the community @David_King!

In SQL a field will always exist, but the value may be nullable. The closest equivalent to an $exists query would be:

SELECT * FROM goods where product IS NOT NULL

For a general guide to roughly equivalent SQL queries, the MongoDB manual has some helpful reference pages:

Typically you will not use identical data models in MongoDB vs RDBMS. I included more on this in a discussion yesterday, so please read my related post for more details:

Regards,
Stennie

1 Like

@Stennie_X, thanks for the explanation.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.