If two operations conflict with each other during database operations, the results may be abnormal. I have written this code before: user_Utf8Provider.remove ({},{}, function (result) {user_Utf8Provider.insert (user, {}, function (result) {console. log (create Default User) ;};}); on
If two operations conflict with each other during database operations, the results may be abnormal. I have written this code before: user_Utf8Provider.remove ({},{}, function (result) {user_Utf8Provider.insert (user, {}, function (result) {console. log ("create default user") ;};}); on
If two operations conflict with each other during database operations, the results may be abnormal.
I have written such a piece of code before:
User_Utf8Provider.remove ({},{}, function (result) {user_Utf8Provider.insert (user ,{}, function (result) {console. log ("create default user ");});});
The purpose of the above Code is to delete the previous user every time the server is restarted in the development phase, and then create a new user. On my machine, this can be achieved, however, on a colleague's machine, how can I not add new users? I just deleted the previous data and found that database operations were asynchronous, the following method can be used to meet this requirement:
User_Utf8Provider.remove ({}, {safe: true}, function (result) {user_Utf8Provider.insert (user, {safe: true}, function (result) {console. log ("create default user ");});});
Original article address: the atomicity of mongodb. Thank you for sharing it with the original author.