在這裏我有兩個文件,我需要查詢得到title="post one"
和comments: userid="1"
我想獲得只有上述條件的意見。並非所有評論。如何從文檔中使用PHP Mongo獲取嵌套陣列
`{ 「_id」:物件( 「53b7f2383ed7755c2400002e」), 「稱號」: 「後一」, 「作家」: 「鮑勃」, 「貼」:ISODate(「2014-07-05T12 :40:24.0Z「), 」網頁瀏覽「:NumberInt(5), 」評論「:{ 」0「:{ 」參數userid「: 」1「, 」文本「: 」這是酷「 }, 「1」:{ 「參數userid」: 「2」, 「文本」: 「這是不好的」 }, 「3」:{ 「參數userid」: 「3」, 「文本」: 「這是badexample」 } 「4」:{ 「參數userid」: 「4」, 「文本」: 「否感謝名單」 } 「5」:{ 「參數userid」: 「1」, 「文本」:「否其優良的」 } 「6」:{ 「用戶ID」: 「1」, 「文」: 「測試」 } 「7」:{ 「用戶id」: 「1」, 「文」: 「未見其精確定不壞」 } 「8」:{ 「用戶id」: 「1」, 「文」: 「測試DDD」 }
}} `
{ "_id": ObjectId("53b7f2383ed7755c2400002e"), "title": "Post Two", "author": "bob", "posted": ISODate("2014-07-05T12:40:24.0Z"), "pageViews": NumberInt(5), "comments": { "0": { "userid": "1", "text": "this is cool" }, "1": { "userid": "2", "text": "this is bad" }, "3": { "userid": "3", "text": "this is badexample" } "4": { "userid": "4", "text": "No Thanx" } } }
對於一些相關的討論參見:[只檢索MongoDB中集合的對象陣列中的查詢元件](http://stackoverflow.com/questions/3985214/retrieve-only-the-queried-element-in -an對象陣列合mongodb的收集)。 – Stennie