Export one object with mongoexport, how to specify _id?

前端 未结 5 470
萌比男神i
萌比男神i 2020-12-18 08:23

I\'m trying to export just one object with mongoexport, filtering by its ID.

I tried:

mongoexport -d \"kb_development\" -c \"articles\" -q \"{\'_id\'         


        
5条回答
  •  孤城傲影
    2020-12-18 08:52

    I think you should be able to use ObjectId(...) in the query argument to mongoexport:

    mongoexport -d kb_development -c articles -q '{_id: ObjectId("4e3ca3bc38c4f10adf000002")}'
    

    If that does not work, you can use the "strict mode" javascript notation of ObjectIds, as documented here:

    mongoexport -d kb_development -c articles -q '{_id: {"$oid": "4e3ca3bc38c4f10adf000002"}}'
    

    (Also note that strict mode JSON is the format produced by mongoexport)

提交回复
热议问题