I would like to find out how to do the below, without actually doing the DB Query.. i.e. I would like to know if "someData" would pass "whereClause" without putting it in a table and asking for it back again. I.e. Run the logic inside findOne without the overhead of insert and select. Just to make it more fun, please consider that I need to have it thread safe, thats why im messing with a Guid kinda thing below.. Also please note the where clause is probably gonna be more complex than the below, like { a : { $ne : 1 } }
Given Source:
someData = { a: 1, b: 2 };
whereClause = { b: 2 };
My code that needs fixing:
someData.GUID = ObjectId();
// DB QUERY - insert
db.workspace.insert(someData);
whereClause.GUID = inputsValues.GUID;
// Check if the data passes the whereClause
// DB QUERY - findOne
var whereResult = db.workspace.findOne(whereClause);
// DB QUERY - remove
db.workspace.remove({ "GUID": whereClause.GUID });
if (whereResult == null)
alert("Fail");
else
alert("Pass");
In SQL what I want can be expressed kinda like this: (pseudo syntax)
if (
Select Count(*) from ((Select 1 as A, 2 as B) Data where B = 2) Result
) = 1 then 'pass' else 'fail'
The above query never actually touches a table - that is my main goal.