Skip to content

Instantly share code, notes, and snippets.

@Rajavasanthan
Created June 19, 2025 14:33
Show Gist options
  • Save Rajavasanthan/f0f5594fd238006753af7415dd62fcf3 to your computer and use it in GitHub Desktop.
Save Rajavasanthan/f0f5594fd238006753af7415dd62fcf3 to your computer and use it in GitHub Desktop.
// SELECT * FROM films;
db.films.find();
// SELECT title, year FROM movies
db.films.find({}, { title: 1, releaseYear: 1 });
// NO equal SQL for this
db.films.find({}, { title: 0, releaseYear: 0 });
// SELECT * FROM films WHERE title='Leo'
db.films.find({ title: "Leo" }, { title: 1 });
// NO equal SQL for this
db.films.find({ title: "Leo" }, { title: 1, _id: 0 });
// SELECT title FROM films WHERE title='Leo' AND releaseYear=2024
db.films.find({ title: "Leo", releaseYear: 2024 }, { title: 1 });
// SELECT * FROM films WHERE releaseYear > 2022
db.films.find({ releaseYear: { $gt: 2022 } }, { title: 1 });
// NO equal SQL for this
db.films.find({ languages: { $in: ["Kanada"] } });
// SELECT title FROM films WHERE boxOfficeCollection > 300 AND budget > 300
db.films
.find(
{
"stats.boxOfficeCollection": { $gte: 300 },
"stats.budget": { $gte: 300 },
},
{ title: 1, "stats.boxOfficeCollection": 1 }
)
.pretty();
// SELECT title FROM films WHERE releaseYear > 2022 OR ratting > 4
db.films
.find({
$or: [
{
releaseYear: {
$gt: 2022,
},
},
{
ratting: {
$gt: 4,
},
},
],
})
.pretty();
db.films.find({ title: { $exists: false } });
db.films.updateOne({ title: "Leo" }, { $set: { title: "Leo 2" } });
db.films.deleteOne({});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment