@vkarpov15 yeah It is fixed. But now I have another question :D I have field in my schema which uniqueness option true. When I create a new document which is not unique I got mongo error so I need to put mongoose validation for that field again to get Validation Error. Is there an other way? Because every new document I need to check all docs in db. Is there any performance issue about this?
The preferred way is to deal with the mongoerror - there's really no way for mongoose to enforce a uniqueness constraint without mongod's help in the general case at the moment. However, if you have just one app server and aren't really concerned about the race conditions, you can write a pre('save') middleware that first queries the db and checks for any matching docs
if you have an index in place this should be fast, but again it has a race condition. I'd still recommend creating a unique index on the mongod side, either using mongoose schema unique property or manually, and just handling the mongoerror if it happens