Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
find()mongodb文档asp内部数组元素条件_Mongodb - Fatal编程技术网

find()mongodb文档asp内部数组元素条件

find()mongodb文档asp内部数组元素条件,mongodb,Mongodb,我需要打印整个文档,其中title='sports' //STUDENT collection { 'name':'qwerty', 'college':'123' , 'BLOGS':[ {'title':'music', 'desc':'party' } , {'title':'sports', 'desc':'cricket' } ] } 不是为我工作,救命啊 使用仅返回BLOGS数组的第一个匹配元素,其中title字段的值为“sports”: 样本输出: d

我需要打印整个文档,其中title='sports'

//STUDENT collection

{ 

'name':'qwerty',

 'college':'123' ,

'BLOGS':[ 

{'title':'music', 'desc':'party' } 
,

{'title':'sports', 'desc':'cricket' }

 ] 

}
不是为我工作,救命啊

使用仅返回
BLOGS
数组的第一个匹配元素,其中
title
字段的值为
“sports”

样本输出:

db.STUDENT.find({ "BLOGS.title": "sports" }, 
    {
        "_id": 0, 
        "BLOGS": {
            "$elemMatch": { "title": "sports" }
        }
    }
)
使用仅返回
BLOGS
数组的第一个匹配元素,其中
title
字段的值为
“sports”

样本输出:

db.STUDENT.find({ "BLOGS.title": "sports" }, 
    {
        "_id": 0, 
        "BLOGS": {
            "$elemMatch": { "title": "sports" }
        }
    }
)
/* 0 */
{
    "BLOGS" : [ 
        {
            "title" : "sports",
            "desc" : "cricket"
        }
    ]
}