0

If I put a variable with an undefined value into the "scope" parameter of mapReduce(), then the map function will receive the variable with a null value (instead of the undefined value). Is that correct?

For example (javascript skeleton for the "mongo" command):

db.mycol.mapReduce(
                        f_map,
                        f_reduce,
                        {
                            scope: { myvar:   undefined}
                        }
                  );

function f_map()
{
    print("myvar: " + myvar);
}

That will print "myvar: null" (instead of "myvar: undefined") into the server log (into the replicaset member log). Are undefined values converted automatically to null values when passing through mapReduce()?

1 Answer 1

1

Yes undefined values get translated into null values in mongodb's v8 engine.

The reason for this is to keep backwards compatibility with the older Spider Monkey JS engine and not break existing code that relied on that behaviour.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.