简体   繁体   English

如何在MongoDB的数组中从嵌入式文档打印值?

[英]How can I print value from embedded document in side an array in MongoDB?

Here is the document from which I want to print name value (Despacito) only. 这是我仅要从中打印名称值(Despacito)的文档。

{
    "movie" : [
            {
                    "song" : {
                            "name" : "Despacito"
                    }
            }
    ]
}

movie is an array, so you can access the index by movie[0]. movie是一个数组,因此您可以通过movie [0]访问索引。 Then song is an object. 然后,歌曲是一个对象。 You can just do 你可以做

result.movie[0].song.name

DEMO DEMO

 var result = { "movie" : [ { "song" : { "name" : "Despacito" } } ] }; console.log(result.movie[0].song.name); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Mongoose将值推入MongoDB中嵌入式文档中的数组? - How do I $push a value to an array within an embedded document in MongoDB using Mongoose? 如何在 mongodb 中涉及数组或其他类型的嵌入或嵌套文档的更新操作中使用变量? - How can I use variables in an update operation in mongodb that involves an array or another type of embedded or nested document? 如何使用MongoDB从嵌入在数组中的文档中删除属性? - How to remove property from document embedded in array using MongoDB? 如何在 MongoDB 中的数组中获取嵌入文档(使用 Mongoose) - How to get embedded document in an array in MongoDB (with Mongoose) 如何在流星Mongodb的服务器端插入文档? - How can I insert document on server side for Meteor Mongodb? 如何通过使用嵌入式文档的值有效地从JSON文档数组中访问JSON文档? - How do I efficiently access JSON documents from an array of JSON documents, by using value of embedded document? 请问如何更新嵌套的 mongodb 嵌入文档,我有这样的文档结构 - Please how can i update a nested mongodb embedded document, I have a document structure like this 如何将变量从嵌入式SVG发送到HTML文档? - How can I send a variable from an embedded SVG to the HTML document? 如何从MongoDB文档更新匹配某个值的数组? - How do I update an array from MongoDB document that match a certain value? 我如何按MongoDB文档中的字段对数组排序 - How can I sort array by a field inside a MongoDB document
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM