Created
February 7, 2022 16:12
-
-
Save johnlpage/ea0cb95fd29f29e100665f3417e51582 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sign = (doc,fields) => { | |
let toSign="" | |
fields.forEach(f => { toSign += parseFloat(doc[f]) + "." } ) | |
toSign = toSign.replace(/NaN/,'.') | |
print(`Signing: ${toSign}`) | |
iv = 56781234 | |
for(c=0;c<toSign.length;c++) { | |
v = parseInt(toSign[c]) | |
if(isNaN(v)) v=10; //Dots etc | |
v += 1; //No point multiplying 0 by anything | |
print(v) | |
iv = (iv + ( 227 ** ((c+1)%6) * v)) % 1048576 | |
} | |
return iv | |
} | |
doc = {_id: "test", x:1,y:1,s:5.5} | |
doc.cksum = sign(doc) | |
try { db.readonlyfields.insertOne( doc) } catch(e) {print(e.errmsg)} | |
{ "acknowledged" : true, "insertedId" : "test" } | |
try { db.readonlyfields.updateOne( {_id:"test"}, {$set:{b:2}}) } catch(e) {print(e.errmsg)} | |
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 } | |
try { db.readonlyfields.updateOne( {_id:"test"}, {$set:{x:2}}) } catch(e) {print(e.errmsg)} | |
Document failed validation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment