Home:ALL Converter>what will be mangoose equivalent of this oracle query

what will be mangoose equivalent of this oracle query

Ask Time:2020-10-13T00:34:54         Author:uddi baba

Json Formatter

I am trying to convert this oracle query to Mongoose equivalent. I am trying to do it using findOneAndUpdate, but don`t know how to convert this NVL thing. here is my query

 Update Authentication
           Set Datetime   = Sysdate,
               Isactive   = 'Y',
               Version    = '1.0.0',
               Firstlogin = Nvl(Firstlogin, Sysdate),
               Lastlogin  = Sysdate

This is what i have tried. I have used $cond and inside it ifNull, but its not working, Also used $cond and then and if condition to check for null, bot no luck at all.

function createOrUpdate() {
        let filter = { count: { $lt: 4 } };
        let options = { upsert: true, returnOriginal: false, multi: true };
        let userID = "asdfasdf"
        let testUser = {
            userId: userID,
            userNick: "user.nickName",
            reqTime: 1,
        }
        let update = {
            $inc: { count: 1 }, $addToSet: {
                "users": {
                    $each: [testUser],
                }
            },
            $cond: [
                {
                    $ifNull: ['$roomName', true], $set: {
                        roomName: "1112"
                    },
                    $set: {
                        roomName: "1112"
                    }
                },  

            ]
        };
        // {  },
        // let update = {
        // $cond: {
        //     if: {
        //         $or:[{$eq: ["roomName",null]},{$eq: ["roomName",""]}]
        //     },
        //     then: {
        //         $set: {
        //             roomName: "varxy"
        //         }
        //     },
        //     else: {
        //         $set: {
        //             roomName: "roomName"
        //         }
        //     }
        // },
        //     $inc: { count: 1 }, 
        //     "$set": { "users":{ "userId": userID, "user": testUser } }
        //     }        
        ModelRooms.findOneAndUpdate(
            filter,
            update,
            options, function (err, doc) {
                if (err) {
                    logger.error(`Error:: ${err}`);
                }
                else {
                    logger.info(`User added to room`);
                }
            });
    }

Author:uddi baba,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/64321787/what-will-be-mangoose-equivalent-of-this-oracle-query
yy