zeldor.biz

Linux, programming and more

Copyright © 2025
Log in

MongoDB on macOS

October 23, 2019 by Igor Drobot Leave a Comment

MongoDB is a cross-platform document-oriented database. Classified as a NoSQL database. MongoDB can be used for rapid development and storing of Big Data while the database is very scalable.

Installation on macOS

1
brew cask install mongodb

brew cask install mongodb

Start MondoDB by launching the MongoDB.app icon in your Applications.

Development

Install python3 MongoDB module to beginn to interact with the databse

1
pip3 install pymongo

pip3 install pymongo

1
2
3
4
5
6
7
import pymongo
from pymongo import MongoClient
 
client = MongoClient('localhost', 27017)
db = client.mydb
users = db.users
user1 = {"username": "nick", "password": "mypassword", "favorite_number": 445, "hobbies": ["python", "pizza"]}

import pymongo from pymongo import MongoClient client = MongoClient('localhost', 27017) db = client.mydb users = db.users user1 = {"username": "nick", "password": "mypassword", "favorite_number": 445, "hobbies": ["python", "pizza"]}

Another test – bulk data insert:
1
2
test_users = [{"username": "ann", "password": "12345"}, {"username": "jane", "password": "blue"}]
bulk_insert = users.insert_many(test_users)

test_users = [{"username": "ann", "password": "12345"}, {"username": "jane", "password": "blue"}] bulk_insert = users.insert_many(test_users)

Count how many users you have:
users.find().count()

users.find().count()

Count user with specific favorite_number:
users.find({"favorite_number": 445}).count()

users.find({"favorite_number": 445}).count()

Filed Under: Linux Tagged With: Big Data, MongoDB, python3

Categories

Archives

Tags

apache2 Apple arduino ARM Automation backup bash Cisco Cluster Corosync Database Debian Debian squeeze DIY DNS Fedora FTP Fun Icinga Ipv6 KVM Linux LVM MAC OS X Monitoring MySQL Nagios Nginx openSUSE OpenVPN PHP Proxy Python python3 qemu RAID rsync Samba security ssh Ubuntu virtualization Windows Windows 7 Wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *

Yeaaah Cookie! We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok