Robomongo and MongoDB - initial setup on Mac
1. Install MongoDB :
2. Run MongoDB server :
5. Create Example Database in RoboMongo :
Step 1 : Create Database
Step 2 : Create Collection ( Collection of Documents/Tables )
Step 3 : Create Document/Table
Step 4 : Insert data in Document
Query Test in Python ( using pymongo)
import pymongo
# Connecting with server
client = pymongo.MongoClient('10.100.101.11', 27017)
# Get database
db = client.database_name
# Query Single value
queryResult = db['Models'].find({'assetname':"mesh01"})
# Query with wild card value
queryResult = db['Models'].find({'assetname':{'$regex': 'mesh'}})
# Query Multiple values
queryResult = db['Models'].find({'assetname':{'$in':["mesh01", "rig04"]}})
for entry in queryResult:
print entry
# Copying Database
import pymongo
mongoServerIP = '10.217.130.12'
mongoServerPort = 27017
client = pymongo.MongoClient(mongoServerIP, mongoServerPort)
client.copy_database('databaseName', 'databaseName_copy', mongoServerIP + ':'+ mongoServerPort)
[ Documentation : https://docs.mongodb.com/manual/reference/operator/query/ ]
Unity C# (Adding data to collection)
private static MongoClient client;
private static IMongoDatabase database;
private static IMongoCollection collection;
public static void MDBConnect()
{
client = new MongoClient("mongodb://127.0.0.1:27017/");
// "/' frontslash after port number is important
database = client.GetDatabase("DatabaseName");
collection = database.GetCollection("CollectionName");
}
public static void SendEvent(string action, string information)
{
var entry = new BsonDocument {
{ "action", action },
{ "info", information}
};
Debug.Log(client.ListDatabaseNames());
collection.InsertOneAsync(entry);
}
- Download tgz or zip file from MongoDB website
- Extract tgz or zip file in home directory
- eg : /Users/userName/mongodb_x86_64-3.0.0
- Add path of mongoDB directory in PATH
2. Run MongoDB server :
- Create a directory for primary DB path.
- /Users/userName/mongodb_x86_64-3.0.0/data/db
- Run Command
-
/Users/userName/mongodb_x86_64-3.0.0/bin/mongod --dbpath /Users/userName/mongodb_x86_64-3.0.0/data/db --bind_ip 0.0.0.0 -v
3. Install RoboMongo :
- Download RoboMongo from http://robomongo.org/
- Drop downloaded/extracted folder in Applications folder (/Applications)
4. Run RoboMongo and Connect with MongoDB :
5. Create Example Database in RoboMongo :
Step 1 : Create Database
Step 2 : Create Collection ( Collection of Documents/Tables )
Step 3 : Create Document/Table
Step 4 : Insert data in Document
Query Test in Python ( using pymongo)
import pymongo
# Connecting with server
client = pymongo.MongoClient('10.100.101.11', 27017)
# Get database
db = client.database_name
# Query Single value
queryResult = db['Models'].find({'assetname':"mesh01"})
# Query with wild card value
queryResult = db['Models'].find({'assetname':{'$regex': 'mesh'}})
# Query Multiple values
queryResult = db['Models'].find({'assetname':{'$in':["mesh01", "rig04"]}})
for entry in queryResult:
print entry
# Copying Database
import pymongo
mongoServerIP = '10.217.130.12'
mongoServerPort = 27017
client = pymongo.MongoClient(mongoServerIP, mongoServerPort)
client.copy_database('databaseName', 'databaseName_copy', mongoServerIP + ':'
Unity C# (Adding data to collection)
private static MongoClient client;
private static IMongoDatabase database;
private static IMongoCollection
public static void MDBConnect()
{
client = new MongoClient("mongodb://127.0.0.1:27017/");
// "/' frontslash after port number is important
database = client.GetDatabase("DatabaseName");
collection = database.GetCollection
}
public static void SendEvent(string action, string information)
{
var entry = new BsonDocument {
{ "action", action },
{ "info", information}
};
Debug.Log(client.ListDatabaseNames());
collection.InsertOneAsync(entry);
}
Comments