Meteor:Accounts.createUser抛出异常:meteor.roles。$ name_1 dup key

时间:2015-10-25 13:45:03

标签: javascript meteor meteor-blaze meteor-accounts meteor-autoform

尝试在注册时向<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.gcmclient" > <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="com.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.example.gcm" /> </intent-filter> </receiver> <service android:name=".service.GcmService" android:exported="false"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </service> <service android:name=".service.LoggingService" android:exported="false" /> <activity android:name=".MainActivity" android:label="@string/app_name" android:clearTaskOnLaunch="false" android:finishOnTaskLaunch="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 集合添加新用户。

在Meteor的客户端,我调用服务器方法将用户添加到users集合

users

第一次只在Meteor.methods({ createUserServer : function (user) { // On server-side, Accounts.createUser is essentially // blocking (Fibers): it waits for the user to be // created, and then returns its newly generated id. try { var userId = Accounts.createUser(user) console.log('user ID: ' , userId); return { success:true , message : userId } } catch (e) { console.log('Meteor Exception: ',e); return { success : false , message : e.reason } } } }) 集合上很好地添加了添加,但在此之后,我得到了这个例外:

users

我检查了数据库上的Meteor Exception: { [MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: meteor.roles.$name_1 dup key: { : null }] stack: [Getter] }集合,我发现只有一个文档:

roles - &gt;返回 - &gt; db.roles.find()

我不确定那是什么类型的问题?

1 个答案:

答案 0 :(得分:0)

我明白了。

出于某种原因,name文档被作为索引并且是唯一的,这导致了上述冲突,通过删除该索引,现在工作正常:

Meteor.roles._ensureIndex('name', {unique: 1})

现在我很高兴:)

参考:https://github.com/orionjs/orion/issues/239