Ticket: Migration connection error

Hi @kanikasingla, i am trying to execute the python movie_last_updated_migration.py script, and I am getting the following error,
raise ConfigurationError(str(exc)) pymongo.errors.ConfigurationError: None of DNS query names exist: _mongodb._tcp.mflix.e1ypo.mongodb.net., _mongodb._tcp.mflix.e1ypo.mongodb.net.vuhl.root.mrc.local., _mongodb._tcp.mflix.e1ypo.mongodb.net.veteransunited.com., _mongodb._tcp.mflix.e1ypo.mongodb.net.root.mrc.local., _mongodb._tcp.mflix.e1ypo.mongodb.net.vamclo.com., _mongodb._tcp.mflix.e1ypo.mongodb.net.mortgageresearchcenter.com., _mongodb._tcp.mflix.e1ypo.mongodb.net.d.vu.local., _mongodb._tcp.mflix.e1ypo.mongodb.net.p.vu.local., _mongodb._tcp.mflix.e1ypo.mongodb.net.uc.veteransunited.com., _mongodb._tcp.mflix.e1ypo.mongodb.net.be11136764.prod.datalake.ellieservices.com., _mongodb._tcp.mflix.e1ypo.mongodb.net.elliemae.com., _mongodb._tcp.mflix.e1ypo.mongodb.net.Home.

My py script is
`from pymongo import MongoClient, UpdateOne
from pymongo.errors import InvalidOperation
from bson import ObjectId
import dateutil.parser as parser

“”"
Ticket: Migration
Update all the documents in the movies collection, such that the “lastupdated”
field is stored as an ISODate() rather than a string.
The parser.parse() method can transform date strings into ISODate objects for
us. We just need to make sure the correct operations are sent to MongoDB!
“”"

ensure you update your host information below!

host = “mongodb+srv://m220student:m220password@mflix.e1ypo.mongodb.net”
mflix = MongoClient(host)[“mflix”]

TODO: Create the proper predicate and projection

add a predicate that checks that the “lastupdated” field exists, and then

checks that its type is a string

a projection is not required, but may help reduce the amount of data sent

over the wire!

predicate = {“lastupdated”: {"$exists": True,"$type":“string”}}
projection = None

cursor = mflix.movies.find(predicate, projection)

this will transform the “lastupdated” field to an ISODate() from a string

movies_to_migrate =
for doc in cursor:
doc_id = doc.get(’_id’)
lastupdated = doc.get(‘lastupdated’, None)
movies_to_migrate.append(
{
“doc_id”: ObjectId(doc_id),
“lastupdated”: parser.parse(lastupdated)
}
)

print(f"{len(movies_to_migrate)} documents to migrate")

try:
# TODO: Complete the UpdateOne statement below
# build the UpdateOne so it updates the “lastupdated” field to contain
# the new ISODate() type
bulk_updates = [UpdateOne(
{"_id": movie.get(“doc_id”)},
{"$set": {“lastupdated”:movie.get(“lastupdated”)}}
) for movie in movies_to_migrate]

# here's where the bulk operation is sent to MongoDB
bulk_results = mflix.movies.bulk_write(bulk_updates)
print(f"{bulk_results.modified_count} documents updated")

except InvalidOperation:
print(“no updates necessary”)
except Exception as e:
print(str(e))’

Can I get some insights on this please?

Please make sure you are able to connect to mongo cluster from your local system like you have whitelisted the IP address and there is no firewall issue when connecting through your system.

Kanika

It is very strange that your DNS resolver tries all the following:

It is only supposed to look for _mongodb._tcp.mflix.e1ypo.mongodb.net without a trailing dot.

Do you happen to have a trailing dot at the end of the URI? If not, do you have a special DNS resolver that looks at all these extra domains. If no trailing dot and no special DNS, then may be a virus or trojan horse. You should try the public DNS servers 8.8.8.8 and 8.8.4.4 from google.

1 Like