2015-12-22

MongoDB - "Like" statement

db.COLLECTION_NAME.find({  "FIELD_NAME" : /.*STRING_HERE.*/  });

2015-12-10

2015-12-03

MongoDB - Create a full text search index

db.COLL_NAME.createIndex( 
   { 
      FIELD_NAME : "text"  
   } 
);

MongoDB - Unique compound index creation

db.COLL_NAME.createIndex(  
   {  
       FIELD_NAME : 1
       , FIELD_NAME_2: 1  
   }
   , { unique: true }  
);
 

MongoDB - Unique index creation

db.COLL_NAME.createIndex( { FIELD_NAME : 1 }, { unique: true } );
 

2015-12-02

MongoDB - Execute a custom script file and export the results to a flat file using the command line

mongo localhost:3001/DATABASE_NAME SCRIPT_FILE_NAME.js >> TARGET_FILE_NAME.EXTENSION

MongoDB - Export query to flat file from the command-line

mongo SERVER_NAME_OR_IP:PORT_NUMBER/DATABASE_NAME --eval "var c = db.COLLECTION_NAME.find(); while(c.hasNext()) {printjson(c.next())}" >> TARGET_FILE_NAME.TARGET_FILE_NAME_EXTENSION

Actual example:
mongo localhost:3001/meteor --eval "var c = db.mycoll.find(); while(c.hasNext()) {printjson(c.next())}" >> test.txt

Another example/thread at:
http://stackoverflow.com/questions/12823990/how-to-get-mongo-command-results-in-to-a-flat-file

MongoDB - Meteor command-line import

mongoimport --jsonArray -h localhost:3001 -d meteor -c COLLECTION_NAME --file "/PATH_TO_FILE/FILE.EXTENSION"

PS. Specify the address (-h) of your Meteor's MongoDB instance.

2015-12-01

MongoDB - How to insert integer numbers

db.COLLECTION_NAME.insert({ FIELD_NAME : NumberInt(NUMERIC_VALUE) });