Posts

Showing posts with the label MongoDB

Difference between createIndex() and ensureIndex() in java using mongodb

In Java,  DBCollection.ensureIndex()  was deprecated in version 2.12 and removed in version 3.0.  DBCollection.createIndex()  is the one that should be used. It was used to create indexes on collections whereas  ensureIndex()  creates an index on the specified  field  if the index does not already exist. Moreover, when we execute  createIndex()  twice the second execution will just  fail  whereas with  ensureIndex()  you can invoke it multiple times and it will  not fail

How to load a js file to mongoDB

load ( filename . js ) mongo localhost:27017/mydb myfile.js print ( 'From file 1' ); load ( 'myFileTwo.js' ); // Load other js file . myFileTwo.js print ( 'From file 2' ); MongoShell > mongo myFileOne . js Output From file 1 From file 2

import json collection file in mongodb

You are probably running this command under mongo shell. As you can see in the path program files/mongodb/server/3.2/bin there is no command under mongod as mongoimport. So in order to solve the problem, navigate your cmd prompt to the file and without using mongo shell(mongo) run the command in cmd prompt. mongoimport --drop -d school -c students students.json

MongoDB Tutorial

Image