at least one in mongodb
at least one in mongodb
I have a database related to movies. This is how I inserted my data in the database:
db.Movieinfo.insert(
"MovieID":1,
"MovieName":"iron man",
"Actor":"Robert downey",
"ReleaseDate":2008,
"GotOscars":1,
)
But when I do the following to get the list of movies which returns only movies that have won at least one oscar or more: db.Movieinfo.find("MovieName":1,"GotOscars":$gte:1)
, it gives all the movies that haven't won oscar also. Could anyone please help me with this? Thank you in advance.
db.Movieinfo.find("MovieName":1,"GotOscars":$gte:1)
2 Answers
2
The mongoDB search query uses: db.collection.find(<query>, <projection>)
db.collection.find(<query>, <projection>)
To find the names of all movies with more or equal to one oscar use:
db.Movieinfo.find("GotOscars":$gte:1, "MovieName":1);
To find full movie details of movies with more or equal to one oscar use:
db.Movieinfo.find("GotOscars":$gte:1)
You can learn more about in the official documentation here.
try this
db.Movieinfo.find("GotOscars":$gte:1)
https://docs.mongodb.com/manual/reference/method/db.collection.find/
you were passing 2 arguments and another argument was considered as projection.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy
db.Movieinfo.find( "GotOscars":$gte:1 )
– Mohamed Sameer
Sep 16 '18 at 6:53