Mongodb导出子字段项

时间:2013-10-02 15:49:00

标签: regex mongodb mongoexport

我有下面显示的mongodb数据,我正在转储到csv并且可以正常生成这些数据。

{ "_id" : { "$oid" : "57770104c6" }, "data" : { "username" : "23359244-649151A3C397",   "loginCount" : 0, "createDate" : "1379193232", "modifiedDate" : "1379193232", "roleId" : 1, "dateOfBirth" : "1379109600", "userProfileStateId" : 5, "cellPhoneVerificationSent" : false, "page" : 0, "limit" : 9, "nameForSearch" : "Jomo Kenyatta" } }

我想只转储“nameForSearch”的子字段项结果,例如“Jomo Kenyatta” - 但我一直得到0结果。谁能指出我可能做错了什么?

mongoexport -d refugees -c stat -f "data" -q '{"createdAt":{"$gte":new Date(1379192400000)}, "data.nameForSearch" : {$regex: "^name"}}'--csv >  refugees.csv

解决: 我必须将子字段或子字段名称添加到原始文档名称,即data.nameForSearch,并根据需要将搜索结果转储到搜索中。

mongoexport -d refugees -c stat -f data.nameForSearch -q '{"createdAt":{"$gte":new Date(1379192400000)}}'--csv >  refugees.csv

0 个答案:

没有答案