如何使用"find"在Perl API中搜索"_id => OBjectID("id")"

Man*_*ani 8 perl mongodb

我必须在我的Mongo中找到一种"_id",我可以使用Mongo shell来实现它,而且我不能使用Perl API来做到这一点.

我正在努力(mongo shell):

./mongo
use my_db
db.my_collection.find({_id : ObjectId("4d2a0fae9e0a3b4b32f70000")})
Run Code Online (Sandbox Code Playgroud)

它有效!(返回),但我无法使用Perl API,

$mongo->my_db->my_collection(find({_id => "ObjectId(4d2a0fae9e0a3b4b32f70000"}));
Run Code Online (Sandbox Code Playgroud)

不起作用,因为"ObjectId"不是字符串,但如果你这样做,

./mongo
use my_db
db.my_collection.find({_id : "ObjectId(4d2a0fae9e0a3b4b32f70000)"})
Run Code Online (Sandbox Code Playgroud)

也不行,我猜Perl API正在做它^

现在,我必须知道我是如何做到的:

db.my_collection.find({_id : ObjectId("4d2a0fae9e0a3b4b32f70000")})
Run Code Online (Sandbox Code Playgroud)

使用Perl API.

Wei*_*yan 8

实施似乎发生了变化.

$mongo->my_db->my_collection(
  find({ _id => MongoDB::OID->new(value => "4d2a0fae9e0a3b4b32f70000")})
);
Run Code Online (Sandbox Code Playgroud)