【发布时间】:2018-01-17 18:25:09
【问题描述】:
我在 mongoDB 的集合中有一些字段。 我已经尝试导出所有内容。 看起来像这样
{"_id":{"$oid":"5a5ef05dbe83813f55141a51"},"comments_data":{"id":"211","comments":{"paging":{"cursors":{"after":"WzZANVFV4TlRVME5qUXpPUT09","before":"WTI5dEF4TlRVNE1USTVNemczTXpZAMk56YzZANVFV4TlRBMU9ERTFNQT09"}},"data":[{"created_time":"2018-01-04T09:29:09+0000","message":"Super","from":{"name":"M Mun","id":"1112"},"id":"1111"},{"created_time":"2018-01-07T22:25:08+0000","message":"Happy bday..Godbless you...","from":{"name":"L1","id":"111"},"id":"1111"},{"created_time":"2018-01-10T00:22:00+0000","message":"Nelson ","from":{"name":"Boon C","id":"1111"},"id":"10111"},{"created_time":"2018-01-10T01:07:19+0000","message":"Thank to SingTel I like to","from":{"name":"Sarkar WI","id":"411653482605703"},"id":"10155812413346677_10155825869201677"}]}},"post_id":"28011986676_10155812413346677","post_message":"\"Usher in the New Year with deals and rewards that will surely perk you up, exclusively for Singtel customers. Find out more at singtel.com/rewards\"",
但现在我只想导出一个字段,即集合中“cmets_data”中的“消息”。
我试过用这个mongoexport --db sDB --collection sTest --fields data.comments_data --out test88.json
但是当我检查我导出的文件时,它只包含类似这样的内容
{"_id":{"$oid":"5a5ef05dbe83813f55141a51"}}
这是我没有预料到的。
我只想要"message":"Happy bday..Godbless you..."之类的东西
但是当我使用db.sTest.find({}, {comments_data:1, _id:0})在 mongoshell 查询时,我可以大致得到我想要的。
【问题讨论】:
标签: mongodb mongoexport