Meteor: Disallow user from selecting id's when inserting documents -


when using mini-mongo insert documents collection user pass _id field , _id set on document long string or objectid (and doesnt collide existing id). doesnt seem sensible me. want _id of documents generated server, always, dont end db both strings (potentially of different length) , objectids exist _ids.

is there simple way achieve this? right best can think of checking id in deny rule (where _id either set meteor or value user provided) , if it's not type/length want change it, requires checks avoid duplicate ids. not difficult seems overly complex basic this.

reviewing response, here's answer:

deny inserts. create method, collectioninsert(document), checks if _id field specified.

meteor.methods({   collectioninsert: function(document) {     if (document && document._id) {       delete document._id;     }     // returns _id generated     return collection.insert(document);   } }); 

in today's versions of meteor (0.8 , higher) server , client generate same _id in case anyway. using method should ensure client simulates field insert , server's version of generated _id authoritative.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -