Posts

Showing posts with the label pymongo

MongoDB tip: mtools setup

This is just a quick guide on setting up mtools , there will be a separate post with examples. Determine the version of Redhat I am working with [root@msdlva-dsnopm02 apps]# lsb_release -a LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch Distributor ID: RedHatEnterpriseServer Description:    Red Hat Enterprise Linux Server release 7.3 (Maipo) Release:        7.3 Codename:       Maipo Start working on installing the required modules. [root@msdlvd-dsnavl02 ~]# pip install ordereddict Collecting ordereddict   Downloading ordereddict-1.1.tar.gz Installing collected packages: ordereddict   Running setup.py install for ordereddict ... done Successfully installed ordereddict-1.1 [root@msdlvd-dsnavl02 ~]# pip install argparse Collecting argparse ...

MongoDB tip: comparing field cross collection using python

Image
The goal is to find anything that's in col2, but not in col1. col1 contains the following col2 contains the following Note, the field to compare in both collection need not to be in order as seen in the images. Again, I am trying to find what's missing in the first set from the second set.  from pymongo import MongoClient import bson client=MongoClient(host="mongodb://10.155.228.75:21001") db=client.testJoe col1=db.col1.distinct("compID"); col2= db.col2.distinct("compID"); col1= [int(x) for x in col1] x = set(col2) - set(col1) print(int(list(x)[0])) we see the output is 7, which is the missing number from col1