Exemplo n.º 1
0
import os
import sys

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path = [os.path.join(SCRIPT_DIR + '/../')] + sys.path

from mongojoin import MongoJoin
from mongojoin import MongoCollection
from utils import print_dict, print_list

if __name__ == "__main__":

    m_1 = MongoCollection("test", "supplier", ["supplier_id", "name"], {})

    c_1 = m_1.get_mongo_cursor()

    print "************************ COLLECTION : SUPPLIER ************************"
    c = c_1.find({})
    print_list(c)

    aggregator = MongoJoin(m_1, m_1, ["supplier_id"])

    print "\n************************ INNER JOIN **********************"
    print_dict(aggregator.inner())
    print "\n********************** LEFT OUTER JOIN **********************"
    print_dict(aggregator.left_outer())
    print "\n********************** RIGHT OUTER JOIN *********************"
    print_dict(aggregator.right_outer())
    print "\n********************** FULL OUTER JOIN *********************"
    print_dict(aggregator.full_outer())
Exemplo n.º 2
0
import os
import sys

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path = [os.path.join(SCRIPT_DIR + '/../')] + sys.path

from mongojoin import MongoJoin
from mongojoin import MongoCollection
from utils import print_dict, print_list

if __name__ == "__main__":

    m_1 = MongoCollection("test", "supplier", ["supplier_id", "name"],
                          {"supplier_id": 1001})
    m_2 = MongoCollection("test",
                          "order", ["supplier_id"], {"supplier_id": 1002},
                          host='localhost')

    c_1 = m_1.get_mongo_cursor()
    c_2 = m_2.get_mongo_cursor()

    print "************************ COLLECTION : SUPPLIER ************************"
    c = c_1.find({})
    print_list(c)

    print "************************ COLLECTION  : ORDER **************************"
    c = c_2.find({})
    print_list(c)

    aggregator = MongoJoin(m_1, m_2, ["supplier_id"])
Exemplo n.º 3
0
import os
import sys

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path = [os.path.join(SCRIPT_DIR + "/../")] + sys.path

from mongojoin import MongoJoin
from mongojoin import MongoCollection
from utils import print_dict, print_list

if __name__ == "__main__":

    m_1 = MongoCollection("test", "supplier", ["supplier_id"], {})
    # replace host accordingly
    m_2 = MongoCollection("test", "order", ["supplier_id"], {}, host="localhost")

    c_1 = m_1.get_mongo_cursor()
    c_2 = m_2.get_mongo_cursor()

    print "************************ COLLECTION : SUPPLIER ************************"
    c = c_1.find({})
    print_list(c)

    print "************************ COLLECTION  : ORDER **************************"
    c = c_2.find({})
    print_list(c)

    aggregator = MongoJoin(m_1, m_2, ["supplier_id"])

    print "\n************************ INNER JOIN **********************"
    print_dict(aggregator.inner())
Exemplo n.º 4
0
import os
import sys

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path = [os.path.join(SCRIPT_DIR + '/../')] + sys.path

from mongojoin import MongoJoin
from mongojoin import MongoCollection
from utils import print_dict, print_list

if __name__ == "__main__":

    m_1 = MongoCollection("test", "supplier", [], {})

    c_1 = m_1.get_mongo_cursor()

    aggregator = MongoJoin(m_1, m_1, ["supplier_id"])

    print "\n************************ INNER JOIN **********************"
    print_dict(aggregator.inner())