MongoDB stores data in flexible, JSON-like documents. The document model maps to object in your application code, making data easy to work with. MongoDB is a distributed database at its core.
Here. Be careful, need 3.4 or later.are notes on how to install MongoDB on RHEL7.
MongoDB is a document store (and essentially a database). Spark is a computing engine and not a store. When used together, Spark jobs can be executed directly on operational data sitting in MongoDB.
On Ubuntu 17.10: sudo apt install monogodb
Make sure to start mongod service. Nothing will work otherwise: sudo service mongodb start
To change location of data store:
sudo vi /etc/mongodo.conf
# modify the following line --> dbpath=/new/db/path
# update permissions
sudo chown mongodb:sudo /new/db/path
sudo chmod 770 /new/db/path
sudo service mongodb restart
Troubleshooting information: https://stackoverflow.com/questions/45691032/mongod-service-start-exits-with-code-100
Check ownership of /path/to/db should be owned by user mongodb
Check that port 27017 is allowed. If not: (ubuntu) ufw allow from 127.0.0.1 to 127.0.0.1 port 80 proto tcp
.
Link to official documentation
# connect to MongoDB instance running on port 27017
mongo
# display all databases
show dbs
# to switch databases, issue the use command
use <database>
show collections # it will show "dispatch"
# find operation
db.dispatch.find().pretty()
# drop, everything!
db.dispatch.drop()
Add this class in the package in which you will access MongoDB. Easy!
** Casbah has been deprecated. Use https://docs.mongodb.com/ecosystem/drivers/scala/ **
import com.mongodb.casbah.MongoClient
object MongoFactory {
private val SERVER = "localhost"
private val PORT = 27017
private val DATABASE = "plus"
private val COLLECTION = "dispatch"
val connection = MongoClient(SERVER)
val collection = connection(DATABASE)(COLLECTION)
}
- Insert new document
val builder: mutable.Builder[(String, Any), DBObject] = MongoDBObject.newBuilder
builder += "hello" -> "world"
builder += "foo" -> "bar"
val o = builder.result()
MongoFactory.collection.insert(o)
- Iterate over all documents, optionally remove
for (i <- MongoFactory.collection.find()) {
println(i) // use
//MongoFactory.collection.remove(i) // remove
}
MongoBooster is a lightweight GUI for visualizing your data store. The application is distributed using AppImage format (which is v. cool)
To run: ./mongobooster-4.1.3-x86_64.AppImage
MongoDB Compass is helpful for database visualization and manipulation.
Here are some query examples:
{ uuid: 'ut001' }