The Not Only Structured Query Language (NoSQL) database is not a relational database; instead, data can be stored in key-value, JSON, document, columnar, or graph formats. They are frequently used in big data and real-time applications. We will learn here how to access NoSQL data using MongoDB, and we assume you have the MongoDB server configured properly and on:
- We will need to establish a connection with the Mongo daemon using the
MongoClient
object. The following code establishes the connection to the default host,localhost
, and port (27017
). And it gives us access to the database:
from pymongo import MongoClient client = MongoClient() db = client.test
- In this example, we try to load the
cancer
dataset available in scikit-learn to the Mongo database. So, we first get the breast cancer dataset and convert it to a pandas DataFrame:
from sklearn.datasets import load_breast_cancer import pandas as pd cancer = load_breast_cancer() data = pd.DataFrame(cancer.data, columns=[cancer...