MongoError: Index with name: c2_emails.$.address already exists with a different name

After upgrade mongodb version to 4.2.
The app won’t start correctly.

 MongoError: Index with name: c2_emails.$.address already exists with a different name

I’m using these packages


ostrio:cookies

meteor-base@1.4.0             # Packages every Meteor app needs to have
mobile-experience@1.0.5       # Packages for a great mobile UX
mongo@1.7.0                   # The database Meteor supports right now
tracker@1.2.0                 # Meteor's client-side reactive programming library

standard-minifier-css@1.5.4   # CSS minifier run for production mode
standard-minifier-js@2.5.2    # JS minifier run for production mode
es5-shim@4.8.0                # ECMAScript 5 compatibility for older browsers.
ecmascript@0.13.2             # Enable ECMAScript2015+ syntax in app code
shell-server@0.4.0            # Server-side component of the `meteor shell` command

static-html

akryum:vue-component
deanius:promise
dynamic-import
accounts-password@1.5.2

aldeed:schema-index

browser-policy
littledata:synced-cron
reywood:publish-composite


underscore
fourseven:scss
cdn
dburles:collection-helpers
natestrauser:publish-performant-counts
force-ssl
accounts-google
accounts-facebook
service-configuration
alanning:roles

ccorcos:subs-cache
fortawesome:fontawesome
server-render
routepolicy

The email field is

  emails: {
        type: Array,
        minCount: 1,
        maxCount: 1
    },
    'emails.$': {
        type: Object
    },

    'emails.$.address': {
        type: String,
        regEx: SimpleSchema.RegEx.EmailWithTLD,
        index: true,
        unique: true,
        sparse: true
    },
    'emails.$.verified': {
        type: Boolean
    },

Meteor packages versions

accounts-base@1.4.5
accounts-facebook@1.3.2
accounts-google@1.3.3
accounts-oauth@1.1.16
accounts-password@1.5.2
akryum:vue-component@0.15.2
akryum:vue-component-dev-client@0.4.7
akryum:vue-component-dev-server@0.1.4
alanning:roles@3.2.2
aldeed:collection2@3.0.6
aldeed:schema-index@3.0.0
allow-deny@1.1.0
autoupdate@1.6.0
babel-compiler@7.4.2
babel-runtime@1.4.0
base64@1.0.12
binary-heap@1.0.11
blaze-tools@1.0.10
boilerplate-generator@1.6.0
browser-policy@1.1.0
browser-policy-common@1.0.11
browser-policy-content@1.1.0
browser-policy-framing@1.1.0
caching-compiler@1.2.1
caching-html-compiler@1.1.3
callback-hook@1.2.0
ccorcos:subs-cache@0.9.12
cdn@1.3.0
check@1.3.1
coffeescript@1.0.17
cosmos:browserify@0.10.0
dburles:collection-helpers@1.1.0
ddp@1.4.0
ddp-client@2.3.3
ddp-common@1.4.0
ddp-rate-limiter@1.0.7
ddp-server@2.3.0
deanius:promise@3.1.3
deps@1.0.12
diff-sequence@1.1.1
dynamic-import@0.5.1
ecmascript@0.13.2
ecmascript-runtime@0.7.0
ecmascript-runtime-client@0.9.0
ecmascript-runtime-server@0.8.0
ejson@1.1.1
email@1.2.3
es5-shim@4.8.0
facebook-oauth@1.6.0
fetch@0.1.1
force-ssl@1.1.0
force-ssl-common@1.1.0
fortawesome:fontawesome@4.7.0
fourseven:scss@4.12.0
geojson-utils@1.0.10
google-oauth@1.2.6
hot-code-push@1.0.4
html-tools@1.0.11
htmljs@1.0.11
http@1.4.2
id-map@1.1.0
inter-process-messaging@0.1.0
launch-screen@1.1.1
littledata:synced-cron@1.5.1
livedata@1.0.18
localstorage@1.2.0
logging@1.1.20
meteor@1.9.3
meteor-base@1.4.0
minifier-css@1.4.3
minifier-js@2.5.1
minimongo@1.4.5
mobile-experience@1.0.5
mobile-status-bar@1.0.14
modern-browsers@0.1.4
modules@0.14.0
modules-runtime@0.11.0
mongo@1.7.0
mongo-decimal@0.1.1
mongo-dev-server@1.1.0
mongo-id@1.0.7
natestrauser:publish-performant-counts@0.1.2
npm-bcrypt@0.9.3
npm-mongo@3.2.0
oauth@1.2.8
oauth2@1.2.1
ordered-dict@1.1.0
ostrio:cookies@2.6.0
promise@0.11.2
raix:eventemitter@0.1.3
random@1.1.0
rate-limit@1.0.9
reactive-var@1.0.11
reload@1.3.0
retry@1.1.0
reywood:publish-composite@1.7.3
routepolicy@1.1.0
server-render@0.3.1
service-configuration@1.0.11
sha@1.0.9
shell-server@0.4.0
socket-stream-client@0.2.2
spacebars-compiler@1.1.3
srp@1.0.12
standard-minifier-css@1.5.4
standard-minifier-js@2.5.2
static-html@1.2.2
templating-tools@1.1.2
tmeasday:check-npm-versions@0.3.2
tracker@1.2.0
underscore@1.0.10
url@1.2.0
webapp@1.7.5
webapp-hashing@1.0.9

How to resolve this error ?
Or else any solution to use the Mongo 3.6 on Ubuntu 20.04 LTS as it won’t allow the 3.6 installation.

I somehow solved it by downloading the schema-index and change the server.js file

    function ensureIndex(index, name, unique, sparse) {
        // console.log('index, name, unique, sparse', index, name, unique, sparse)
        Meteor.startup(() => {
            try {
                collection.rawCollection().createIndex(index, {
                    background: true,
                    name,
                    unique,
                    sparse,
                });
            } catch (err) {
                // console.error('createIndex err', err)
                // duplicate creating, ignore
            }
        });
    }

    function dropIndex(indexName) {
        // Meteor.startup(() => {
        //     try {
        //         collection.rawCollection().dropIndex(indexName);
        //     } catch (err) {
        //         // console.error('dropIndex err', err)
        //         // no index with that name, which is what we want
        //     }
        // });
    }

Very likely you’ve hit this snag: https://docs.mongodb.com/manual/reference/command/createIndexes/#index-names.

This possibly because you are attempting to create the same index twice, for instance: 1) via unique: true in SimpleSchema and 2) via createIndex. To solve this situation properly, choose only one of these options, then drop all your indexes and restart Mongo.

Edit: Meteor already creates an index for the ‘emails.$.address’ field, AFAIK.

1 Like

Thank you for the explanation ! You’re right and the problem is with “_ensureIndex”, So i only need replacing it with “createIndex” in
aldeed:schema-index . As I don’t wanna change my old working code and ensure the indexes was created therefore i ignored the errors and deployed the newer version to a server with Ubuntu 20.04 LTS / Mongo 4.2x without issue