Question.
I have to find a kind of "_id" in my Mongo, I can do it using the Mongo shell, and I can not do that using Perl API.
I'm trying to do it (mongo shell):
./mongo
use my_db
db.my_collection.find({_id : ObjectId("4d2a0fae9e0a3b4b32f70000")})
It works!(returns), but I can't do that using Perl API,
$mongo->my_db->my_collection(find({_id => "ObjectId(4d2a0fae9e0a3b4b32f70000"}));
Does not work because "ObjectId" is not a string, but if you do,
./mongo
use my_db
db.my_collection.find({_id : "ObjectId(4d2a0fae9e0a3b4b32f70000)"})
Does not work too, I'm guess Perl API are doing it ^
Now, I have to know how I do it:
db.my_collection.find({_id : ObjectId("4d2a0fae9e0a3b4b32f70000")})
using Perl API.
Answer 1.
The implementation seems changed.
$mongo->my_db->my_collection(
find({ _id => MongoDB::OID->new(value => "4d2a0fae9e0a3b4b32f70000")})
);
Answer 2.
I found the solution, you have to do:
$mongo->my_db->my_collection(find({ _id => $mongo->oid("4d2a0fae9e0a3b4b32f70000")}));
출처 : http://stackoverflow.com/questions/4659437/how-to-use-find-to-search-id-objectidid-in-perl-api
'Industry 4.0 > Big Data' 카테고리의 다른 글
PINPOINT 란 (0) | 2017.03.02 |
---|---|
[MongoDB] mongo-2.10.1.jar, junit 쓴 단위 테스트 for JAVA (0) | 2014.12.13 |
[MongoDB] MongoDB 에서 Sequence 사용하기 (0) | 2014.10.07 |
[MongoDB] MongoDB - Java Driver (0) | 2014.10.01 |
[MongoDB] Sequence 사용하기 (0) | 2014.09.22 |
댓글