There is any MD5 or SHA-1 builtin function?

8,190 views
Skip to first unread message

Gabriel Vieira

unread,
Apr 14, 2010, 2:24:20 AM4/14/10
to mongod...@googlegroups.com
Hi there again.

There is any md5 or sha-1 hash builtin fuction in MongoDB? I searched
MongoDB website/documentation but got no results.

Thanks,

--
Gabriel Vieira

Mathias Stearn

unread,
Apr 14, 2010, 2:40:47 AM4/14/10
to mongod...@googlegroups.com
We have the filemd5 command for gridfs, but no other hashing. Do you
have a use case in mind?

> --
> 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.
>
>

Gabriel Vieira

unread,
Apr 14, 2010, 2:47:46 AM4/14/10
to mongod...@googlegroups.com
I could use to generate a MD5 string from another (text, password,
etc) direct in the DB, link relationals DB.

What do you think?

--
Gabriel Vieira

Mathias Stearn

unread,
Apr 14, 2010, 2:55:09 AM4/14/10
to mongod...@googlegroups.com
That sounds like something that would be better done in your
application, rather than the database server. We do use (double)
hashing of passwords so they are not transmitted in the clear. See
http://www.mongodb.org/display/DOCS/Implementing+Authentication+in+a+Driver

On Wed, Apr 14, 2010 at 2:47 AM, Gabriel Vieira

dan90

unread,
Apr 14, 2010, 3:03:41 AM4/14/10
to mongodb-user
Yes, to expand to the limits of my knowledge upon Mathias's point:
there are pure javascript hashing algorithms that you could
hypothetically use - e.g. http://www.movable-type.co.uk/scripts/sha1.html
- but you don't want to, as server-side javascript execution with
db.eval is a blocking operation. You don't want your database pausing
everytime someone generates a password. In any case you'd still have
to have your application code know to call the server-side javascript
function.

--dan()

On Apr 14, 4:55 pm, Mathias Stearn <math...@10gen.com> wrote:
> That sounds like something that would be better done in your
> application, rather than the database server. We do use (double)

> hashing of passwords so they are not transmitted in the clear. Seehttp://www.mongodb.org/display/DOCS/Implementing+Authentication+in+a+...


>
> On Wed, Apr 14, 2010 at 2:47 AM, Gabriel Vieira
>
>
>
> <gabriel.vie...@gmail.com> wrote:
> > I could use to generate a MD5 string from another (text, password,
> > etc) direct in the DB, link relationals DB.
>
> > What do you think?
>

> > On Wed, Apr 14, 2010 at 3:40 AM, Mathias Stearn <math...@10gen.com> wrote:
> >> We have the filemd5 command for gridfs, but no other hashing. Do you
> >> have a use case in mind?
>
> >> On Wed, Apr 14, 2010 at 2:24 AM, Gabriel Vieira
> >> <gabriel.vie...@gmail.com> wrote:
> >>> Hi there again.
>
> >>> There is any md5 or sha-1 hash builtin fuction in MongoDB? I searched
> >>> MongoDB website/documentation but got no results.
>
> >>> Thanks,
>
> >>> --
> >>> Gabriel Vieira
>
> >>> --
> >>> 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 athttp://groups.google.com/group/mongodb-user?hl=en.


>
> >> --
> >> 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 athttp://groups.google.com/group/mongodb-user?hl=en.

Patrick May

unread,
Apr 2, 2011, 5:46:24 PM4/2/11
to Mathias Stearn, mongod...@googlegroups.com

On Apr 14 2010, 2:40 am, Mathias Stearn <math...@10gen.com> wrote:
> We have the filemd5 command for gridfs, but no other hashing. Do you
> have a use case in mind?

I have a decent use case. I need to md5 compound keys in a map
function to avoid creating _id's that are too long.

The compound key is produced by the map function using multiple values
(url + etc). Some data values exceed the length allowable by the
btree indexer. I don't actually need a readable value in the _id, so
I'd be happy to hash these values. All the data is appropriately
stored in the value returned by my map function. But there's no md5
available.

I can implement the desired behavior by iterating over the collection,
doing the calculation externally, updating the rows, then running a
mapreduce. But that doesn't allow mongo to parallelize the mapping
across multiple servers. And seems clunky to run a map step prior to
running mapreduce.

Best,

Patrick

Eliot Horowitz

unread,
Apr 2, 2011, 9:21:51 PM4/2/11
to mongod...@googlegroups.com
hex_md5 is defined in javascript

> hex_md5( "foo" )
acbd18db4cc2f85cedef654fccc4a4d8

Reply all
Reply to author
Forward
0 new messages