My challenge involves working with 2 collections, where I'm attempting to retrieve all records from Coll_A
where a specific field (Field1
) is not present in Coll_B
.
The complicating factor is that the Field1
in
Coll_A</code has trailing white spaces up to a certain length, which are missing in the corresponding collection.</p>
<p>In the query below, the array <code>vals
contains unpadded records, causing inaccurate results when using db.Coll_A.find
.
vals = db.Coll_B.find({},
{"Field1" : 1, _id: 0})
.map(function(a){
return a.Field1;
});
db.Coll_A.find({ "Field1": { $nin: vals }});
I've explored using regex
to handle whitespace differences, but I'm unsure how to apply it in this scenario. Any help would be greatly appreciated. Thank you.