matches.js
function mongoEqual(documentValue,queryOperand) {
    if(documentValue instanceof Array) {
        if(!(queryOperand instanceof Array))
            return false
        if(documentValue.length !== queryOperand.length) {
            return false
        } else {
            return documentValue.reduce(function(previousValue, currentValue, index) {
                return previousValue && mongoEqual(currentValue,queryOperand[index])
            }, true)
        }
    } else if(documentValue instanceof Object) {
        if(!(queryOperand instanceof Object))
            return false

        var aKeys = Object.keys(documentValue)
        var bKeys = Object.keys(queryOperand)

        if(aKeys.length !== bKeys.length) {
            return false
        } else {
            for(var n=0; n<aKeys.length; n++) {
                if(aKeys[n] !== bKeys[n]) return false

                var key = aKeys[n]
                var aVal = documentValue[key]
                var bVal = queryOperand[key]

                if(!mongoEqual(aVal,bVal)) {
                    return false
                }
            }
            // else
            return true
        }
    } else {
        if(queryOperand === null) {
            return documentValue === undefined || documentValue === null
        } else {
            return documentValue===queryOperand
        }
    }
}
function mongoEqual(documentValue,queryOperand) {
    if(documentValue instanceof Array) {
        if(!(queryOperand instanceof Array))
            return false
        if(documentValue.length !== queryOperand.length) {
            return false
        } else {
            return documentValue.reduce(function(previousValue, currentValue, index) {
                return previousValue && mongoEqual(currentValue,queryOperand[index])
            }, true)
        }
    } else if(documentValue instanceof Object) {
        if(!(queryOperand instanceof Object))
            return false

        var aKeys = Object.keys(documentValue)
        var bKeys = Object.keys(queryOperand)

        if(aKeys.length !== bKeys.length) {
            return false
        } else {
            for(var n=0; n<aKeys.length; n++) {
                if(aKeys[n] !== bKeys[n]) return false

                var key = aKeys[n]
                var aVal = documentValue[key]
                var bVal = queryOperand[key]

                if(!mongoEqual(aVal,bVal)) {
                    return false
                }
            }
            // else
            return true
        }
    } else {
        if(queryOperand === null) {
            return documentValue === undefined || documentValue === null
        } else {
            return documentValue===queryOperand
        }
    }
}
function mongoEqual ( documentValue , queryOperand ) { if ( documentValue instanceof Array ) { if ( ! ( queryOperand instanceof Array ) ) return false if ( documentValue . length !== queryOperand . length ) { return false } else { return documentValue . reduce ( function ( previousValue , currentValue , index ) { return previousValue && mongoEqual ( currentValue , queryOperand [ index ] ) } , true ) } } else if ( documentValue instanceof Object ) { if ( ! ( queryOperand instanceof Object ) ) return false var aKeys = Object . keys ( documentValue ) var bKeys = Object . keys ( queryOperand ) if ( aKeys . length !== bKeys . length ) { return false } else { for ( var n = 0 ; n < aKeys . length ; n ++ ) { if ( aKeys [ n ] !== bKeys [ n ] ) return false var key = aKeys [ n ] var aVal = documentValue [ key ] var bVal = queryOperand [ key ] if ( ! mongoEqual ( aVal , bVal ) ) { return false } } // else return true } } else { if ( queryOperand === null ) { return documentValue === undefined || documentValue === null } else { return documentValue === queryOperand } } }
matches any value, with mongo's special brand of very strict object equality and weird null matching
matches any value with mongo s special brand of very strict object equality and weird null matching