本文介绍了使用mongoexport导出一个对象,如何指定_id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅通过mongoexport导出一个对象,并按其ID进行过滤.

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

我尝试过:

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

还有很多变化,但一直在说

and many variations, but it keeps saying

connected to: 127.0.0.1
exported 0 records

(而且我确定集合中有这样的对象)

(and I'm sure there is such an object in the collection)

在mongo shell中,我将使用ObjectId('4e3ca3bc38c4f10adf000002'),但在mongoexport查询中似乎不起作用.

In mongo shell I would use ObjectId('4e3ca3bc38c4f10adf000002'), but it does not seem to work in the mongoexport query.

推荐答案

我认为您应该可以在mongoexport的查询参数中使用ObjectId(...):

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")}'

如果这不起作用,则可以使用ObjectId的严格模式" javascript表示法,如此处所述:

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"}}'

(还要注意严格模式JSON是mongoexport产生的格式)

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

这篇关于使用mongoexport导出一个对象,如何指定_id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 09:12