大佬教程收集整理的这篇文章主要介绍了javascript – 唯一索引不适用于Mongoose / MongoDB,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经尝试了我能想到的一切 – 重新启动(所有)改变语法等
码
添加>>
这是我用来保存实体的方法:
create : function(entity,definition,successFn,errorFn){ var model = mongoose.model(entity); newModel = new model(definition); newModel.save(function(error) { if(error){ if(!errorFn){ throw error; } errorFn(newModel); return; } successFn(newModel); }); }...
<<
var Something = new scheR_828_11845@a({ objectId : ObjectId,name : { type : String,index: { unique: true }},url : { type : String,...etc mongoose.model('Something',Something);
蒙古产量
[conn1] insert xxxxx.agencies 1526ms [conn1] building new index on { name: 1 } for xxxxx.agencies [conn1] insert xxxxx.system.indexes exception 11000 E11000 duplicate key error index: xxxxx.agencies.$name_1 dup key: { : "something" } 4ms [conn1] building new index on { url: 1 } for xxxxx.agencies [conn1] insert xxxxx.system.indexes exception 11000 E11000 duplicate key error index: xxxxx.agencies.$url_1 dup key: { : "http://www.something.com" } 1ms
当我检查MongoHub时,索引不会出现,所以它们看起来不像它们被创建.
这是this question的重复,但它没有一个适用于我的答案.
@H_772_24@db.users.ensureIndex({email:1},{unique:true,sparse:truE});
从蒙古壳
@H_772_24@ @H_772_24@以上是大佬教程为你收集整理的javascript – 唯一索引不适用于Mongoose / MongoDB全部内容,希望文章能够帮你解决javascript – 唯一索引不适用于Mongoose / MongoDB所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。