In today’s tutorial we’ll be looking at: Installing Python Installing PyMongo (Note: PyMongo is a python driver for MongoDB) ..and running mms-agent from your computer(localhost)
I’m using Windows 7 64-bit machine and the installation procedure are shown for the same.
Disclaimer: This is not a paid post and neither am I using any affiliate links in this post. I found MMS(MongoDB Management Service) incredibly useful and I wish I knew about it earlier. The monitoring and alerting services can save your applications reputation, and the backup service will literally save your application in disasters situations.
This installs easy_installer inside C:\Python27\Scripts folder. Easy installer helps in installing drivers. Step 3: Now install Pythons MongoDB driver: PyMongo, with the following command.
Step 5: Log into your MMS account, and download the MMS-AGENT. Extract the mms-agent files into a folder. In our case, we extract it to D:\Python\mms-agent Step 6: Now run the mms-agent with the following command
Step 7: Go to your mms account – Fill the form with the host name, port number and other details
Host Type: Standalone (for this example) Internal Hostname: 127.0.0.1 (ip address for localhost) Port: 27017 (default port used my MongoDB server) DB Username and DB Password: are optional
Now it’ll start to fetch the meta data metrics via your IP address, as the agent is installed on your local machine and it knows your network IP address.
Key things inside your account Events: restart, shut-down or downtime etc Alerts: To alert you in certain situations. You get emails for downtime etc, once setup. Backup: It’s a premium service, which costs a little – backup service is pay-as-you-go service billed via credit card. Users: You could invite people as admin or read only user. This way, you could bring in your team mates/colleagues to analyze and help you in performance tuning of your application. Dashboard: You can customize your dashboard to give you quick view of key aspects of your application is a rich web console. You could have RAM usage statistics or query performance metrics etc. Settings: Normal profile information: email id, password, phone verification etc.
Application Performance Checking with the query performance and your application behavior from the very beginning of application development is recommended. And MMS is a perfect solution for this. This is one of the main reasons for this video tutorial. Running MMS on production servers is easy. You’ve bunch of plugins pre-installed at your host, you just need to enable it and insert the secret keys provided to you inside mms-agent file. But I would recommend you to watch for your application behavior from as early as in its development stage.
Note: You should know the norms of your application behavior, so that you can notice when there is abnormalities. MMS helps you effectively do that.
MongoDB Management Service is free service for getting metrics and setting alerts. And you only pay, if you use backup service and you pay for it as you use it.
Follow the order in this post and make sure to practice all the tutorials and also share your knowledge with our awesome community on our official forum or in respective articles comment section.
If you got to learn anything from our website, then please do not forget to share this page with your friends on Facebook, Google Plus, LinkedIn, Twitter etc..
In this video tutorial we shall illustrate the use of comparison operators in MongoDB.
Comparison Operators $all $in $nin – not in $ne – not equal to $gt – greater than $gte – greater than or equal to $lt – less than $lte – less than or equal to
JavaScript file load.js – in path: C:/test/load.js
db.person.insert({
name : 'Satish',
age : 25,
skills : ['nodejs', 'mongoDB', 'HTML5']
});
db.person.insert({
name : 'Kiran',
age : 27,
skills : ['PHP', 'mySQL', 'HTML5']
});
db.person.insert({
name : 'Sunitha',
age : 24,
skills : ['html', 'ASP']
});
db.person.insert({
name : 'Jyothi',
age : 23,
skills : ['html', 'ASP']
});
db.person.insert({
name : 'Varsha',
age : 30,
skills : ['.NET', 'Java']
});
db.person.insert({
name : 'Amogh',
age : 29,
skills : ['C#', 'ASP']
});
db.person.insert({
name : 'Satish',
age : 25,
skills : ['nodejs', 'mongoDB', 'HTML5']
});
db.person.insert({
name : 'Kiran',
age : 27,
skills : ['PHP', 'mySQL', 'HTML5']
});
db.person.insert({
name : 'Sunitha',
age : 24,
skills : ['html', 'ASP']
});
db.person.insert({
name : 'Jyothi',
age : 23,
skills : ['html', 'ASP']
});
db.person.insert({
name : 'Varsha',
age : 30,
skills : ['.NET', 'Java']
});
db.person.insert({
name : 'Amogh',
age : 29,
skills : ['C#', 'ASP']
});
This JavaScript file contains some simple data, to be inserted into MongoDB server. It contains, persons name, age and skills(in array form) person is the collection name, we’re creating.
C:\mongodb>cd bin
C:\mongodb\bin>mongo 127.0.0.1/satish C:/temp/load.js
MongoDB shell version: 2.4.3
connecting to: 127.0.0.1/satish
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test
C:\mongodb>cd bin
C:\mongodb\bin>mongo 127.0.0.1/satish C:/temp/load.js
MongoDB shell version: 2.4.3
connecting to: 127.0.0.1/satish
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test
Once these data/documents are loaded into new database, we start operating on this data using comparison operator.
$lt – less than – Matches vales that are less than the value specified in the query. $lte – less than or equal to – Matches values that are less than or equal to the value specified in the query.
Here we’re inserting some data/record/documents into the collection person.
Database’s Before running the script
1
2
3
4
5
6
7
8
9
10
11
12
13
C:\>cd mongodb
C:\mongodb>cd bin
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test
> show dbs
admin 0.203125GB
company 0.203125GB
local 0.078125GB
> exit
bye
C:\>cd mongodb
C:\mongodb>cd bin
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test
> show dbs
admin 0.203125GB
company 0.203125GB
local 0.078125GB
> exit
bye
Before running the script, we have only 3 databases.
Running the script
1
2
3
C:\mongodb\bin>mongo 127.0.0.1/satish C:/temp/load.js
MongoDB shell version: 2.4.3
connecting to: 127.0.0.1/satish
C:\mongodb\bin>mongo 127.0.0.1/satish C:/temp/load.js
MongoDB shell version: 2.4.3
connecting to: 127.0.0.1/satish
Here, mongo is the JavaScript shall. 127.0.0.1 is nothing but our localhost. satish is the new database we are creating. C:/temp/load.js is the path of load.js file. We’re loading the contents of load.js file into new database satish.
Database’s After running the script
1
2
3
4
5
6
7
8
9
10
11
12
13
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test
> show dbs
admin 0.203125GB
company 0.203125GB
local 0.078125GB
satish 0.203125GB
> use satish
switched to db satish
> show collections
person
system.indexes
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test
> show dbs
admin 0.203125GB
company 0.203125GB
local 0.078125GB
satish 0.203125GB
> use satish
switched to db satish
> show collections
person
system.indexes
New database satish has been added and it has person collection, which we loaded from the JavaScript file.
Note: This method will be handy while migrating our application from one mongoDB server to another mongoDB server. There is import/export options in mongoDB, but this method is also helpful if we have some custom data to be inserted. nontheless a useful tool to have.
1 or true means, those {key: value} pairs need to be returned. 0 or false means, excluding those {key: value} pairs, all other {key: value} pairs(records) needs to be returned.
> db.info.find({name: 'Apple'}, {product: true, emp_no: false}).forEach(printjson);
Wed May 08 12:11:30.184 JavaScript execution failed: error: {
"$err" : "You cannot currently mix including and excluding fields.
Contact us if this is an issue.",
"code" : 10053
} at src/mongo/shell/query.js:L128
> db.info.find({name: 'Apple'}, {product: 0, emp_no: 1}).forEach(printjson);
Wed May 08 12:11:40.840 JavaScript execution failed: error: {
"$err" : "You cannot currently mix including and excluding fields.
Contact us if this is an issue.",
"code" : 10053
} at src/mongo/shell/query.js:L128
> db.info.find({name: 'Apple'}, {product: true, emp_no: false}).forEach(printjson);
Wed May 08 12:11:30.184 JavaScript execution failed: error: { "$err" : "You cannot currently mix including and excluding fields. Contact us if this is an issue.", "code" : 10053
} at src/mongo/shell/query.js:L128
> db.info.find({name: 'Apple'}, {product: 0, emp_no: 1}).forEach(printjson);
Wed May 08 12:11:40.840 JavaScript execution failed: error: { "$err" : "You cannot currently mix including and excluding fields. Contact us if this is an issue.", "code" : 10053
} at src/mongo/shell/query.js:L128
We can not combine true(1) and false(0) together in the second parameter.
Special Provision! But we can do it with _id(ObjectId)
Operation of second document/record in ‘info’ collection. This illustrates that the syntax for sub-objects, array and the normal key/value pair is same.
If we use findOne() method on this collection, and the condition being the name key, then the oldest document will be returned. Only one key: value pair is returned, as findOne() returns only single object.