簡體   English   中英

如何從 MongoDB 中的復雜數據結構中檢索數據?

[英]How to retrieve data from a complex data structure in MongoDB?

數據:

有沒有辦法通過單個查詢從 MongoDB 的集合中訪問所有這些“lineText”字段?

嘗試這個

db.collectionName.aggregate([
    { $unwind: "$text" },
    { $unwind: "$text.paragraphs" },
    {
        $group: {
            _id: null,
            result: {
                $push: {
                    $arrayElemAt: ["$text.paragraphs.lineText", 0]
                }
            }
        }
    },
    {
        $project: {
            result: {
                $reduce: {
                    input: "$result",
                    initialValue: "",
                    in: { "$concat": ["$$value", "$$this"] }
                }
            }
        }
    }
]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM