草庐IT

validate_unique

全部标签

mongodb - 如何通过 Hibernate OGM 和 JPA 在 MongoDB 中创建 "unique"约束

我试图在非id字段上定义唯一约束。答案似乎显而易见:@Entity@Table(uniqueConstraints=@UniqueConstraint(columnNames={"col1"}))publicclassMyEntity{...}但是,这是行不通的。我已经通过mongo命令行检查了集合中的索引,但是没有唯一索引的踪迹(只生成了一个_id_索引)。我也尝试过使用@Index注释,但并不开心:@Entity@Table(indexes={@Index(name="myIndex",columnList="col1",unique=true)})publicclassMyEnt

python - 非唯一错误 : Tried to save duplicate unique keys

我一直收到上述错误。我删除了设置为唯一的现有数据库字段id。但是在保存时我得到了以下异常raiseNotUniqueError(message%unicode(err))NotUniqueError:Triedtosaveduplicateuniquekeys(E11000duplicatekeyerrorindex:test.users.$id_1dupkey:{:null})我的user表看起来像,classUsers(db.Document,UserMixin):name=db.StringField(max_length=50)email=db.StringField(max_

ruby-on-rails - Rails 3 和 Mongoid : Embedded documents validation

因此,我在嵌入式文档中遇到了一些用户身份验证问题。我有两个文档,一个嵌入另一个。一个企业有很多成员。模型看起来像这样:classMemberincludeMongoid::Documentfield:username,type:Stringfield:password,type:Stringembedded_in:businessvalidates:username,:presence=>true,:uniqueness=>true,:length=>5..60endclassBusinessincludeMongoid::Documentfield:name,type:Stringe

validation - 使用 Backbone.js 验证时如何处理异步调用(特别是唯一性)

这与使用Backbone的客户端或服务器端应用程序相关。我正在尝试创建一个验证函数,对MongoDB或某些REST调用(取决于环境)进行唯一性检查。这两个调用本质上都是异步的;但是,我认为我实际上需要将其阻止在这里以进行验证。如果我不返回任何内容,验证函数将假定验证已通过。我的代码目前在服务器端看起来像这样:isUnique:function(key){vardfdFindOne=this.findOne({key:this.get(key)}),dfd=newDeferred();dfdFindOne.done(function(err,result){console.log(res

node.js - 蒙哥错误: selector must be a valid JavaScript object

我正在为nodejs使用mongodb驱动程序。我在更新记录时遇到错误。{"name":"MongoError","message":"selectormustbeavalidJavaScriptobject","driver":true}这是我的脚本:MongoClient.connect(url,function(err,db){if(err){console.log('UnabletoconnecttothemongoDBserver.Error:',err);return;}varcollName="bank";varSelectParas={"name":"ABC"};var

mongodb - 蒙哥错误: E11000 duplicate key error collection for unique compound index

Questionisrelatedtouniquecompoundindexunlikeothersuchquestionswhichhaveuniqueindexonly.Ialsohavesparse:truefortheindexes.我的收藏中有以下索引[{"v":2,"key":{"_id":1},"name":"_id_","ns":"somedb.votes"},{"v":2,"key":{"answerId":1},"name":"answerId_1","ns":"somedb.votes","sparse":true,"background":true},{"v":

node.js - Loopback ValidationError : The `Role` instance is not valid. 详细信息: `name` 已存在(值: "admin")

我是loopback的新手,但是我按照步骤在server/boot/中安装和构建了我的文件夹(loopback-server),我创建了一个文件script.js并包含了以下代码:module.exports=function(app){varMongoDB=app.dataSources.MongoDB;MongoDB.automigrate('Customer',function(err){if(err)throw(err);varCustomer=app.models.Customer;Customer.create([{username:'admin',email:'admin

MongoDB - "The dollar ($) prefixed field\' $$hashKey\' in\' 字段名".$$hashKey\' is not valid for storage.' "

在尝试更新文档时,我在字段timesToDisplay中收到上述错误。MongoDB版本2.6.7。整个模型:msg={'name':'','template':'','displayDurInMilliSec':0,'timesToDisplay':[],'images':[],'texts':[],'screen':[]}我想我会在其他3个数组字段中遇到同样的错误。我试过使用$set但仍然遇到同样的错误。代码:functionupdateMessage(msg){varconditions={_id:msg._id},update={'name':msg.name,'templat

c# - MongoDB C#Driver 响应。林克 : query for unique instances and using static AsQueryable Properties

我正在处理一个相当大的MongoDB数据库,想知道是否有更有效的方法来处理某些查询。例如,我在数据库中存储了很多Game实例,其中Game类如下所示:publicclassGame{[BsonId]publiclongID{get;set;}//...somemorepropertiespublicListPlayers{get;set;}}其中每个游戏实例都有一个Player列表,后者又具有一些属性,例如Name。在一个View模型中,我想将一个ComboBox绑定(bind)到数据库中所有玩家的名字-但回想一下,同一个玩家可能玩过很多游戏。我按如下方式加载它们:privatevoi