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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -