0

I have some data like this :

db.movies.insert([
    {
        title : "Fight Club",
        writer : "Chuck Palahniuk",
        year : 1999,
        actors : [
          "Brad Pitt",
          "Edward Norton",
        ]
    },
    {
        title : "Pulp Fiction",
        writer : "Quentin Tarantino",
        year : 1994,
        actors : [
          "John Travolta",
          "Uma Thurman",
        ]
    },
    {
        title : "Inglorious Basterds",
        writer : "Quentin Tarantino",
        year : 2009,
        actors : [
          "Brad Pitt",
          "Diane Kruger",
          "Eli Roth",
        ]
    },
    {
        title : "The Hobbit: An Unexpected Journey",
        writer : "J.R.R. Tolkein",
        year : 2012,
        franchise : "The Hobbit",
    },
    {
        title : "The Hobbit: The Desolation of Smaug",
        writer : "J.R.R. Tolkein",
        year : 2013,
        franchise : "The Hobbit",
    },
    {
        title : "The Hobbit: The Battle of the Five Armies",
        writer : "J.R.R. Tolkein",
        year : 2012,
        franchise : "The Hobbit",
        synopsis : "Bilbo and Company are forced to engage in a war against an array of combatants and keep the Lonely Mountain from falling into the hands of a rising darkness.",
    },
    {
        title : "Pee Wee Herman's Big Adventure"
    },
    {
        title : "Avatar"
    }
])

I need to get all movies released before the year 2000 or after 2010, So I'm writing this query:

db.movies.find( {$or: [{"year" : {$gt:2010,$lt:2000}}]})

But I'm not getting any output. Please suggest.

1
  • 2
    it's not possible to have a year greater than 2010 and less than 2000. Commented Aug 9, 2021 at 13:41

1 Answer 1

1

To insert multiple data use db.movies.insertMany([]) option.

to achieve this you can try it like this

db.movies.find({ $or: [{ "year": { $gt: 2010 } }, { "year": { $gt: 2000 } }] })

you can check this for proper documentation here https://docs.mongodb.com/manual/reference/operator/query/or/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.