Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapReduce with GUID in Map function #30

Open
kYann opened this issue Aug 18, 2010 · 2 comments
Open

MapReduce with GUID in Map function #30

kYann opened this issue Aug 18, 2010 · 2 comments

Comments

@kYann
Copy link

kYann commented Aug 18, 2010

Hi,

Seems that there is a bug with using Guid in the map function when doing MapReduce.

If I try to do this.query.Where(c => c.RessourceIdentifier = myGuid).Average(c => c.Value) I get no result if RessourceIdentifier is a Guid.
It works if RessourceIdentifier is a numeric.
Maybe it's because a Guid is stored as binary data in mongodb and in the map function you try to match the Guid as a string.

public class TestGuidIssue
{
public Guid RessourceIdentifier { get; set; }
public int Value { get; set; }
}

@schotime
Copy link
Collaborator

You are correct. If it has to do a map/reduce function (eg.avg, max, min, sum) then it uses javascript, which can't compare a guid because it is binary. This is the same issue if you are doing a (or, ||) comparison in which a guid is also involved.

@Salutoo
Copy link

Salutoo commented Jul 29, 2011

Hi,

How about comparing the BinData- fields ".base64()" (and optionally ".subtype()") in the query? These fields should be available from inside the javascript expressions; something like:

db.TestGuidIssue.find(function() { return this.RessourceIdentifier.base64() == "6hALHeupAkqdKI+R3k945g==" || this.Value > 1}, {Value:1})

works in my mongodb shell without problems. The base64 could be created by c# using

string.Format(""{0}"", Convert.ToBase64String(((Guid)value).ToByteArray()));

I've taken a short look at the NoRM code, but not compiled it or applied any changes myself cause I'm missing both compiler and coding tools other then notepad (^^) at the moment; but I might be able to look into this soon. Why is the Code for Guid's doing "string.Format(""{0}"", value);" anyway? Especially with the if-branch "value is ObjectId || value is Guid". Are there cases which work that way that I miss?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants