I\'m beginner with MongoDB and i\'m trying some stuff. I want to store URL and to avoid duplicate URL I create an unique index on the url. Like that
collection.c
To Use the unique index of the mongodb, you should use the method with 2 parameters where 3rd boolean parameter is for the "unique" index.
mongo.getCollection().ensureIndex(new BasicDBObject("url", 1),"unq_url", true));