0

I have following error occurred

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: E11000 duplicate key error collection: LearningLocker_V2.statements index: id_1 dup key: { : null }

My code is

var express = require('express');
var app = express();
const xapi = require('vtc-lrs');
app.use("/xapi", new xapi());
let options = {
    lrs: new xapi.LRS(),
    connectionString: "mongodb://192.168.1.38:27017/LearningLocker_V2",
    getUser: function (req, username, password) {
        return new xapi.Account("lrsuser", "test123", true, true);
    },
    baseUrl: "http://localhost:8010/xapi"
};
app.use("/xapi", new xapi(options));

In the above code, I connect the mongodb remote server but it's not working. one more thing i use the xapi vts-lrs so don't know how to work with this.

Karthi
  • 102
  • 1
  • 12
  • 1
    The error message says that there's already a record with null as the id. In other words, you already have a statements without an id. Check with LearningLocker_V2.statements.getIndexes() if this is the case and manually remove the unwanted index with LearningLocker_V2.statements.dropIndex(). – Hemadri Dasari Sep 20 '18 at 12:10
  • 1
    Possible duplicate of [E11000 duplicate key error index in mongodb mongoose](https://stackoverflow.com/questions/24430220/e11000-duplicate-key-error-index-in-mongodb-mongoose) – Hemadri Dasari Sep 20 '18 at 12:10
  • You can check the accepted answer here https://stackoverflow.com/questions/24430220/e11000-duplicate-key-error-index-in-mongodb-mongoose. This answer explains in detail and will help you easily to resolve the issue – Hemadri Dasari Sep 20 '18 at 12:11
  • @Think-Twice i already use that solution to drop the index still it's not working that's why i am posting as a new question. – Karthi Sep 20 '18 at 12:17

0 Answers0