I have the following function:

function getidforrec(db::PyObject, collectn::PyObject, rec, 
countername::ASCIIString)
    # check if rec exists; if so get its id
    r = doesrecexist(collectn, rec)
    if r
        return r["_id"]
    else
        r = db[countername][:find_and_modify](
                    query = ["counter" => countername],
                    update = ["\$inc" => ["maxid" => 1]],
                    new = true
            )

        return r["maxid"]
    end
end


When the record rec does not exist in the collection, r is of type Nothing 
in Julia. If the record exists, then r is a Dict. 
When the record does not exist, the above code results in the following 
error:

ERROR: type: non-boolean (Nothing) used in boolean context


One way I can think of dealing with this error is to do:
 

 r = doesrecexist(collectn, rec)
    if typeof != Nothing
        return r["_id"]
    else

                    ... // code for else block here

I was wondering if this is a good way to deal with this, or if another way 
is preferable. 

Thank you.

Reply via email to