title: Create and get indexes from mongoose
body: <p>I am trying to create entries in my database and give them a number. For each <em>new</em> entry I want to assign it an unique index number and then later parse the indexnumber in json. However all I can find in the Mongoose documentation is that you can have mongoose create indexes, calling the createIndex function in MongoDB. How do I see this index and return it? How do I get the index to run from 0 to infinity?</p>
  
  <pre><code>
  const express = require('express');
  const app = express();
  const bodyParser = require('body-parser');
  
  // support parsing of application/json type post data
  app.use(bodyParser.json());
  
  //support parsing of application/x-www-form-urlencoded post data
  app.use(bodyParser.urlencoded({ extended: true }));
  
  const dns = require('dns');
  
  var mongo = require('mongodb');
  var mongoose = require('mongoose');
  
  var cors = require('cors');
  
  // Basic Configuration 
  var port = process.env.PORT || 3000;
  process.env.DB_URI='/MY DATABASE'
  
  mongoose.connect(process.env.DB_URI, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false }).
  catch(error =&gt; handleError(error));
  
  mongoose.connection.on('error', err =&gt; {
    console.log(err);
  });
  
  app.use(cors());
  
  
    //First we create an URL schema and Model in MongoDB.
    const urlSchema = new mongoose.Schema({ 
    original_url: String,
    short_url: {type: Number, index: 'hashed'}
    })
  
  
    const urlModel = mongoose.model('urlModel', urlSchema);
  
  app.post('/PATH', function(req, res, done) {
  
  
    //Now we check if the url was actually valid. 
    //If it's valid we will start creating a model in the DB.
    if(/(^https:\/\/)/.test(req.body.url) || /(^http:\/\/)/.test(req.body.url)) {
      var userUrl = req.body.url;
      var urlNumber = 0;
  
      var input = new urlModel({
        original_url: userUrl
      });
  
    //Check if the url was already added to the database and return a new or updated item.
        var query = {'original_url': userUrl };
  
        urlModel.findOneAndUpdate(query, {'original_url': userUrl}, {new: true, upsert: true}, function(err, updated) {
        if (err) return res.send(500, {error: err});
        var result = {'original_url': updated.original_url}
        res.json(result);
        });
  
  
      input.save(function(err, data) {
        if (err) return console.log('Save gave an error: ' + err);
        done(null, data);
      });
    }
  
    //If url wasn't valid
    else {
      res.json({error: "Invalid url"});
    }
  });
  </code></pre>