Home:ALL Converter>Checking existance of the record and Inserting in MongoDB using Stored Function

Checking existance of the record and Inserting in MongoDB using Stored Function

Ask Time:2017-11-24T22:09:05         Author:Jebin

Json Formatter

Is it good practice to call stored function through c# for inserting a record before checking for its existence or do the same operation through linq in c#?

for e.g

My function is below

function(productid, json) {   
    var exists = db.zProduct.find({"ProductId":productid, "Combinations": { $elemMatch: json }}).count()
    if(exists == 0){
        db.zProductMongoModel.insertOne({"ProductId":productid, "Combinations":json })
        return ("New Document Created")
        }
}

The above code works fine if I call the function though C# but i read from [https://docs.mongodb.com/manual/tutorial/store-javascript-function-on-server/]2 that Do not store application logic in the database. Someone pls advise.

Author:Jebin,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/47474999/checking-existance-of-the-record-and-inserting-in-mongodb-using-stored-function
yy