# LDAP sync user cannot be added to default channel

**URL:** <https://forums.rocket.chat/t/ldap-sync-user-cannot-be-added-to-default-channel/8549>\
**Category:** Community Support\
**Created:** [September 15, 2020, 11:34am UTC](https://forums.rocket.chat/t/ldap-sync-user-cannot-be-added-to-default-channel/8549 "2020-09-15T11:34:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dtvu94](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/dtvu94/32/3199_2.png) [@dtvu94](https://forums.rocket.chat/u/dtvu94)\
**Post date:** [September 15, 2020, 11:34am UTC](https://forums.rocket.chat/t/ldap-sync-user-cannot-be-added-to-default-channel/8549/1 "2020-09-15T11:34:26Z")

</div>

### Description

I receive this error when take a trial on LDAP sync function

**Error** : server.js:204 LDAPSync ➔ error Error creating user BulkWriteError: E11000 duplicate key error collection: meteor.rocketchat\_subscription index: _id_ dup key: { \_id: “aNLpM9qHndnqANgNx” }

#### Step to preproduce:

- Turn on LDAP with setting

#General  
Enable = true  
Login Fallback = true  
Find user after login = true  
Host = example.local  
Port = 8075  
Base DN = dc=example,dc=org

#Authentication  
User DN = cn=admin,dc=example,dc=org  
Password = 12345

#Sync/Import  
Username Field = uid  
User Data Field Map = {“giveName”: “name”, “mail”: “email”}  
Sync User Avatar = true

#User Search  
Search Field = uid

- Save changes
- Execute Synchronization Now

#### Error discover

I find out errors happen at this file: addUserToDefaultChannels.js

- Function: createWithRoomAndUser (line this.insert(subscription))
- Function: createUserJoinWithRoomIdAndUser

I have log the subscriptions and message data to the console and see that the \_id is not input.  
However, the \_id is duplicated in the insert method by mongodb.  
I sync 4 users with username, password, email, name, …

### Server Setup Information

- Version of Rocket.Chat Server: 3.7.0-develop
- Operating System: Linux mint
- Deployment Method: Mannual install
- Number of Running Instances: 1
- DB Replicaset Oplog: default
- NodeJS Version: 12.18.3
- MongoDB Version: 4.2.8
- Proxy: no
- Firewalls involved:no

I also found in bug in the version of Rocket Chat Server: 3.4.2  
with the Server Setup information is default by Rocket.Chat

### Any additional Information

Error log:

 ![Screenshot at 2020-09-15 18-28-22](https://us1.discourse-cdn.com/flex021/uploads/rocketchat/original/2X/1/15fb15cfc02f3068f7f5c64710b40efa4fdf54c8.png)

---

<div class="post-metadata">

**Author:** ![dtvu94](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/dtvu94/32/3199_2.png) [@dtvu94](https://forums.rocket.chat/u/dtvu94)\
**Post date:** [September 15, 2020, 11:35am UTC](https://forums.rocket.chat/t/ldap-sync-user-cannot-be-added-to-default-channel/8549/2 "2020-09-15T11:35:05Z")

</div>

A sample user’s attributes:

 ![Screenshot at 2020-09-15 18-29-43](https://us1.discourse-cdn.com/flex021/uploads/rocketchat/original/2X/9/9336371e57f339dd824322efe2cc84d395108219.png)

---

<div class="post-metadata">

**Author:** ![litoet](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@litoet](https://forums.rocket.chat/u/litoet)\
**Post date:** [September 17, 2020, 3:50am UTC](https://forums.rocket.chat/t/ldap-sync-user-cannot-be-added-to-default-channel/8549/3 "2020-09-17T03:50:03Z")

</div>

Hi,  
I have the same error too. In my case, LDAP’s user has been synchronized but only user, password are not.

---

<div class="post-metadata">

**Author:** ![dtvu94](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/dtvu94/32/3199_2.png) [@dtvu94](https://forums.rocket.chat/u/dtvu94)\
**Post date:** [September 17, 2020, 4:28am UTC](https://forums.rocket.chat/t/ldap-sync-user-cannot-be-added-to-default-channel/8549/4 "2020-09-17T04:28:10Z")

</div>

My current fix is:

- In Accounts.insertUserDoc, I call function `addUserToDefaultChannels` directly instead of using the below code:

> ```
> Meteor.runAsUser(_id, function() {
> return Meteor.call('joinDefaultChannels', options.joinDefaultChannelsSilenced);
> });
> 
> ```

---

<div class="post-metadata">

**Author:** ![litoet](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@litoet](https://forums.rocket.chat/u/litoet)\
**Post date:** [September 17, 2020, 4:32am UTC](https://forums.rocket.chat/t/ldap-sync-user-cannot-be-added-to-default-channel/8549/5 "2020-09-17T04:32:55Z")

</div>

Thanks for shared.  
So when you are using some code like addUserToDefaultChannels you can login RocketChat via LDAP user right now?

---

<div class="post-metadata">

**Author:** ![dtvu94](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/dtvu94/32/3199_2.png) [@dtvu94](https://forums.rocket.chat/u/dtvu94)\
**Post date:** [September 17, 2020, 7:49am UTC](https://forums.rocket.chat/t/ldap-sync-user-cannot-be-added-to-default-channel/8549/6 "2020-09-17T07:49:36Z")

</div>

Yes, I import and use that function directly.

I don’t know why when I use `runAsUser`, and when I sync at least 2 users.

- The first one is always working properly.
- The second one is always crashed because of duplicated ID. Its ID is taken from the first one subscription ID (???). Even I input the subscription \_id, the creation of adding message (because of not silenced) is still failed due to the duplicated key (???)
