MongoDB tip: comparing field cross collection using python
The goal is to find anything that's in col2, but not in col1.
col1 contains the following
Note, the field to compare in both collection need not to be in order as seen in the images.
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
Comments
Post a Comment