I don’t have an exact answer to your question as I use a local mongo server. To me your error looks more like a permission problem at the mongo end.
I have a helper function that will check for and create an index on a collection if it does not exist. It does not use _ensureIndex so it may work around your problem. The function is as follows:
// Attempt to create a mongo Index if it is not already attached to the collection.
function createMongoIndex(collection, collectionName: string, indexName: string, indexKeys: object, indexOptions?: object) {
if (Meteor.isServer) {
Meteor.wrapAsync(collection.rawCollection().indexInformation((err, indexInformation) => {
if (err) {
if (err.message==="no collection") {
consolewarn("[Mongo Index]", collectionName, "- Does not exist (yet)");
err=undefined;
return;
} else {
consoleerror("[Mongo Index]", collectionName, "- FAIL to get index information for", collectionName, err);
throw new Meteor.Error(err);
}
}
//consoledebug(indexInformation);
if (!indexInformation[indexName]) {
consolelog("[Mongo Index]", collectionName, "- Create a mongo index:", indexName);
indexOptions = indexOptions || {};
indexOptions['name'] = indexName;
Meteor.wrapAsync(collection.rawCollection().createIndex(indexKeys, indexOptions, (err2, indexName2) => {
if (err2) {
consoleerror("[Mongo Index]", collectionName, "- FAIL", err2);
throw new Meteor.Error(err);
}
consolelog("[Mongo Index]", collectionName, "- SUCCESS", indexName);
}), collection.rawCollection());
} else {
consoledebug("[Mongo Index]", collectionName, "- Using existing index:", indexName);
}
}), collection.rawCollection());
}
}
When I set up a collection in meteor, I add a line to ensure that the index exists. Whenever the meteor server starts, it ensures that it has the correct indexes on the collection.
// Ensure that additional indexes are present on the Mongo Collection
createMongoIndex( ColSearchIndex, collectionName, 'bySearchTerm', { searchTerm: 1 }, {});
createMongoIndex( ColSearchIndex, collectionName, 'bySearchId', { searchId: 1 }, {});
createMongoIndex( ColSearchIndex, collectionName, 'bySearchCollection', { searchCollection: 1 }, {});
This save me from having to remember to manually add the secondary indexes to a mongo collection. They always appear when the server starts.