{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pymongo\n", "from pymongo import MongoClient" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "client = MongoClient('mongodb://localhost:27017/')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "db = client.restaurants" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "Restaurant = [{\n", " \"address\": {\n", " \"building\": \"1007\",\n", " \"coord\": [ -73.856077, 40.848447 ],\n", " \"street\": \"Morris Park Ave\",\n", " \"zipcode\": \"10462\"\n", " },\n", " \"borough\": \"Bronx\",\n", " \"cuisine\": \"Bakery\",\n", " \"grades\": [\n", " { \"date\": { \"date\": 1393804800000 }, \"grade\": \"A\", \"score\": 2 },\n", " { \"date\": { \"date\": 1378857600000 }, \"grade\": \"A\", \"score\": 6 },\n", " { \"date\": { \"date\": 1358985600000 }, \"grade\": \"A\", \"score\": 10 },\n", " { \"date\": { \"date\": 1322006400000 }, \"grade\": \"A\", \"score\": 9 },\n", " { \"date\": { \"date\": 1299715200000 }, \"grade\": \"B\", \"score\": 14 }\n", " ],\n", " \"name\": \"Morris Park Bake Shop\",\n", " \"restaurant_id\": \"30075445\"\n", "}]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db = client.restaurants\n", "db.publis.insert_many(Restaurant)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{u'cuisine': u'Bakery', u'borough': u'Bronx', u'name': u'Morris Park Bake Shop', u'restaurant_id': u'30075445', u'grades': [{u'date': {u'date': 1393804800000L}, u'grade': u'A', u'score': 2}, {u'date': {u'date': 1378857600000L}, u'grade': u'A', u'score': 6}, {u'date': {u'date': 1358985600000L}, u'grade': u'A', u'score': 10}, {u'date': {u'date': 1322006400000L}, u'grade': u'A', u'score': 9}, {u'date': {u'date': 1299715200000L}, u'grade': u'B', u'score': 14}], u'address': {u'building': u'1007', u'street': u'Morris Park Ave', u'zipcode': u'10462', u'coord': [-73.856077, 40.848447]}, u'_id': ObjectId('5e15e2a11b546c0478eca6b9')}\n" ] } ], "source": [ "publis = db.publis.find()\n", "for publi in publis:\n", " print(publi)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{u'cuisine': u'Bakery', u'restaurant_id': u'30075445', u'_id': ObjectId('5e15e2a11b546c0478eca6b9'), u'borough': u'Bronx', u'name': u'Morris Park Bake Shop'}\n" ] } ], "source": [ "publis = db.publis.find({},{\"restaurant_id\" : 1,\"name\":1,\"borough\":1,\"cuisine\" :1});\n", "for publi in publis:\n", " print(publi)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{u'cuisine': u'Bakery', u'restaurant_id': u'30075445', u'borough': u'Bronx', u'name': u'Morris Park Bake Shop'}\n" ] } ], "source": [ "publis = db.publis.find({},{\"restaurant_id\" : 1,\"name\":1,\"borough\":1,\"cuisine\" :1,\"_id\":0});\n", "for publi in publis:\n", " print(publi)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\Amine\\Anaconda2\\lib\\site-packages\\ipykernel_launcher.py:2: DeprecationWarning: database_names is deprecated. Use list_database_names instead.\n", " \n" ] }, { "data": { "text/plain": [ "[u'dblp', u'local', u'restaurants']" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "client = MongoClient('mongodb://localhost:27017/')\n", "client.database_names()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\Amine\\Anaconda2\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: collection_names is deprecated. Use list_collection_names instead.\n", " \"\"\"Entry point for launching an IPython kernel.\n" ] }, { "data": { "text/plain": [ "[u'system.indexes', u'publis']" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.collection_names()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.15" } }, "nbformat": 4, "nbformat_minor": 2 }