我有一些这样的数据:
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年之后发布的所有电影,所以我写了这个查询:
db.movies.find( {$or: [{"year" : {$gt:2010,$lt:2000}}]})但是我没有得到任何输出。请提个建议。
发布于 2021-08-09 15:00:43
要插入多个数据,请使用db.movies.insertMany([])选项。
要实现这一点,您可以像这样尝试
db.movies.find({ $or: [{ "year": { $gt: 2010 } }, { "year": { $gt: 2000 } }] })您可以在此处查看适当的文档https://docs.mongodb.com/manual/reference/operator/query/or/
https://stackoverflow.com/questions/68713025
复制相似问题