首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mongodb中的or运算符

mongodb中的or运算符
EN

Stack Overflow用户
提问于 2021-08-09 13:37:07
回答 1查看 28关注 0票数 0

我有一些这样的数据:

代码语言:javascript
复制
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"
    }
])

我需要获得在year 2000之前或2010年之后发布的所有电影,所以我写了这个查询:

代码语言:javascript
复制
db.movies.find( {$or: [{"year" : {$gt:2010,$lt:2000}}]})

但是我没有得到任何输出。请提个建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-09 15:00:43

要插入多个数据,请使用db.movies.insertMany([])选项。

要实现这一点,您可以像这样尝试

代码语言:javascript
复制
db.movies.find({ $or: [{ "year": { $gt: 2010 } }, { "year": { $gt: 2000 } }] })

您可以在此处查看适当的文档https://docs.mongodb.com/manual/reference/operator/query/or/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68713025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档