我是MongoDB的新手并且现在正在学习。在这里,我遇到了以下无法查询的问题。下面是我的JSON数据,当我试图通过使用以下db.ERP.find({“title”:“ERP”})找到“标题”:“ERP”时,即使有数据,它也不会获取任何数据。此外,查找数据“标识符”的声明是什么:“0750652071”,“类别”:[“商业与经济学”]。
任何人都可以帮我解决这个问题吗?
Json数据:
{
"_id" : ObjectId("56a6d9c13cd5c314da703c80"),
"kind" : "books#volumes",
"totalItems" : NumberInt(1088),
"items" : [
{
"kind" : "books#volume",
"id" : "7r2cTflTfpQC",
"etag" : "sEiEfpm5JFQ",
"volumeInfo" : {
"title" : "ERP",
"subtitle" : "The Implementation Cycle",
"authors" : [
"Stephen Harwood"
],
"publisher" : "Butterworth-Heinemann",
"publishedDate" : "2003",
"industryIdentifiers" : [
{
"type" : "ISBN_10",
"identifier" : "0750652071"
},
{
"type" : "ISBN_13",
"identifier" : "9780750652070"
}
],
"readingModes" : {
"text" : false,
"image" : true
},
"pageCount" : NumberInt(183),
"printType" : "BOOK",
"categories" : [
"Computers"
],
"averageRating" : 4.0,
"ratingsCount" : NumberInt(2),
},
"saleInfo" : {
"country" : "US",
"saleability" : "NOT_FOR_SALE",
"isEbook" : false
}
},
{
"kind" : "books#volume",
"id" : "3j86qt9VQ2kC",
"etag" : "MQN5u7Pj6yo",
"volumeInfo" : {
"title" : "ERP: Making It Happen",
"subtitle" : "The Implementers' Guide to Success with Enterprise Resource Planning",
"authors" : [
"Thomas F. Wallace",
"Michael H. Kremzar"
],
"publisher" : "John Wiley & Sons",
"publishedDate" : "2002-07-15",
"industryIdentifiers" : [
{
"type" : "ISBN_13",
"identifier" : "9780471217039"
},
{
"type" : "ISBN_10",
"identifier" : "0471217034"
}
],
"readingModes" : {
"text" : false,
"image" : true
},
"pageCount" : NumberInt(384),
"printType" : "BOOK",
"categories" : [
"Business & Economics"
],
"averageRating" : 4.0,
"ratingsCount" : NumberInt(4),
},
"saleInfo" : {
"country" : "US",
"saleability" : "FOR_SALE",
"isEbook" : true
}
}
]
}
感谢您的帮助!
答案 0 :(得分:0)
要搜索tile
为ERP
的数据,请使用以下语法:
db.collection.find({"items.volumeInfo.title":"ERP"})
使用identifier
:0750652071
和categories
查找数据:[ "Business & Economics"]
使用以下语法:
db.collection.find({ "items.volumeInfo.industryIdentifiers.identifier" : "0750652071", "items.volumeInfo.categories" : { $in : [ "Business & Economics"] } })
如果您只想要符合条件的第一项,请在查询{"items.$" : 1}
中包含以下字段,如下所示:
db.collection.find(
{
"items.volumeInfo.industryIdentifiers.identifier" : "0750652071",
"items.volumeInfo.categories" : { $in : [ "Business & Economics"] }
},
{ "items.$" : 1 }
);