the database action insert seems synchronous returning _id right after insertion, therefore no callback needed here.
the question lies on _id being generated (and checked), since seems fast synchronous action done on minimongo, yet there no full list of _id of collection, how’s possible minimongo check whether _id duplicated or not??
when using collection.insert
on client, _id
generated on client using random uuid algorithm, hence seemingly latency compensated client-side insertion.
collection.insert
being implemented special case of meteor.method
, know @ same time client simulation run on client, corresponding server operation triggered, client document sent server along locally generated _id
.
on server, there's check see if _id
correct (truly unique) , server acknowledge valid insertion client.
if client generated _id
not unique after all, insert fail "duplicate key error" (this happen 0.001% of time - probability lower, , have resubmit client form or whatever).
to answer question, _id
can generated in browser in case of client insert, it's validity checked on server.
edit : assumed meteor trying recover duplicate key error , generate new key avoid duplicity , propagate on client, tested use case , found out wrong, @tom freudenberg pointing out.
Comments
Post a Comment