Java with md5 in key problem

60 views
Skip to first unread message

Gontran Magnat

unread,
Jan 7, 2011, 11:42:13 AM1/7/11
to mongodb-user
Hello all,

I'm having a problem while using mongoDb with Java.

I'm inserting documents in a collection using an md5 key as id.
When I look for these objects using their id in the mongo client, I
find them.
But when I look for them from my java application, I cannot find any.

Here is the peace of code:


String ick_to_use = md5(ick); //ick is just a normal String object.
DBObject icDoc = _ichm.findOne(new BasicDBObject("_id", ick_to_use));
if (icDoc == null) {
icDoc = new BasicDBObject("_id", ick_to_use);
}
else{
System.out.println("index already exists");
}
_ichm.save(icDoc);


When I call this piece of code without the md5 encoding, I find some
not null icDoc.
But as soon as I add the md5 encoding, no way to find them.

Do you have an idea?
Thanks in advance.

Scott Hernandez

unread,
Jan 7, 2011, 12:06:36 PM1/7/11
to mongod...@googlegroups.com
What does your md5 function look like? Are you returning a string?

Also, what does your shell session look like when you search?

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Gontran Magnat

unread,
Jan 10, 2011, 7:59:42 AM1/10/11
to mongodb-user
Thanks to your questions, I paid a little more attention to my md5
function and I was not using it properly. The generated chain was
always different... Obviously it couldn't work.

Thanks a lot.

FYI, I was using this for Java implementation of md5:
http://www.twmacinta.com/myjava/fast_md5.php#software
Reply all
Reply to author
Forward
0 new messages