Golang MongoDB Import issue - mongodb

Facing issue importing golang mongodb driver.
go get -u go.mongodb.org/mongo-driver/mongo
go get -u go.mongodb.org/mongo-driver/mongo#~1.0.0
package go.mongodb.org/mongo-driver/mongo: unrecognized import path "go.mongodb.org/mongo-driver/mongo" (https fetch: Get https://go.mongodb.org/mongo-driver/mongo?go-get=1: dial tcp: lookup go.mongodb.org:
no such host)

I would suggest using the mgo library.
import (
mgo "gopkg.in/mgo.v2"
)
You can find more information about this library here: https://gopkg.in/mgo.v2
I used it for multiple websites and it worked like a charm every time.

It seems to be a network issue. Try some another network connection which is not ruled under firewall.
Or else you can use go mod to resolve dependencies automatically.
I am also using the same driver for mongo DB and it is working perfectly fine.
Kindly check here - Golang-Mongo-Driver-Example

Related

flask_pymongo : PyMongo vs MongoClient : [SSL: CERTIFICATE_VERIFY_FAILED]

I have a huge flask application and I use the PyMongo class from flask_pymongo for MongoDB operations. My issue is in development environment.
I have a MONGO_URI in my config.py like this:
MONGO_URI = "mongodb+srv://username:password#cluster-name.pihvl.gcp.mongodb.net/db_name?retryWrites=true&w=majority"
Usage in my app looks like this:
# This is how I have initialized it in '__init__.py'
from flask_pymongo import PyMongo
mongo = PyMongo(app)
# This is how I access collections in the specified DB
document = mongo.db[collection_name].find() # Throws the below error
This worked fine until a couple days ago when I reinstalled Windows and also Python from scratch.
Now the same code throws the following error:
pymongo.errors.ServerSelectionTimeoutError: cluster-name-shard-00-01.pihvl.gcp.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
But using MongoClient instead of PyMongo works just fine, like this:
# Using MongoClient and setting 'ssl_cer_reqs'
from flask_pymongo import MongoClient
import ssl
mongo = MongoClient(app.config['MONGO_URI'], ssl_cert_reqs=ssl.CERT_NONE)
# This works just fine
document = mongo[db_name][collection_name].find()
Questions
What changed with PyMongo when I reinstalled everything? I don't want to use MongoClient simply for the fact that there are over 100 endpoints and it is a nightmare to shift now, and also I prefer PyMongo because I don't have to specify the db_name in every query, it gets that from the MONGO_URI.
What am I missing and how do I make it work with PyMongo? Is there a way to set the ssl_cert_reqs while using PyMongo?
Something in the certificate chain will have changed. pymongo has specific documentation on how to troubleshoot this issue:
https://pymongo.readthedocs.io/en/stable/examples/tls.html#troubleshooting-tls-errors
IMPORTANT: Do this only if you're facing this issue in development environment
All I had to do was add &ssl=true&ssl_cert_reqs=CERT_NONE to my MONGO_URI in my Development Configuration so now my uri would change from:
mongodb+srv://username:password#cluster-name.pihvl.gcp.mongodb.net/db_name?retryWrites=true&w=majority
to:
mongodb+srv://username:password#cluster-name.pihvl.gcp.mongodb.net/db_name?retryWrites=true&w=majority&ssl=true&ssl_cert_reqs=CERT_NONE
pip install certifi
import pymongo
import certifi
myclient = pymongo.MongoClient(CONNECTION_STRING, tlsCAFile=certifi.where())
...

pymongo ServerSelectionTimeoutError with a valid mongo URL

I've been having issues while connecting to a MongoDB database using pymongo.
I use valid URLs, since my colleagues are using the same and it works fine for them, but I keep getting ServerSelectionTimeoutError.
The databases are hosted on MongoAtlas, do you have any idea about what the issue is?
Any issue with a ServerSelectionTimeoutError is a connection issue with the targeted database.
It turns out MongoAtlas has a nice documentation about those: https://docs.atlas.mongodb.com/troubleshoot-connection/
In my case, the issue was that I was on a network with a firewall that closed the needed 27017 port, a simple change of network did the trick.

Importing collections breaks Meteor app deployed with mup

My Meteor app is running on a Digital Ocean droplet.
Meteor: v1.5.3
Server: Ubuntu 14.04.5 x 64
It deploys fine with mup but when I use Studio 3T to import the collections from my old 1.2 app, I see continual error messages in the console like:
GET http://xxx.xx.xx.xx/sockjs/info?cb=u7lbhqd_js net::ERR_CONNECTION_REFUSED
GET requests for resources including images and routes are being refused. The app does run but very slowly and most images are not showing. It is not consistent; the same image will be missing, then appear when I return to the route.
I have imported the same JSON collections to my localhost version and they run perfectly.
I am connecting to the live database by forwarding the mongo instance to localhost with:
ssh -L 4321:localhost:27017 -i ~/.ssh/id_rsa root#xxx.xx.xx.xx
All the imported collections look fine on the live database. I can edit values in documents OK, it's only when I import an entire collection from a JSON file that it goes wrong. And I can't see why updating the collections would interfere with the GET requests.
Has anybody had a similar problem / any idea how to figure out what's going wrong?

Error : No unix socket support on windows connecting mongodb

I'm using robomongo tool to access mongodb. When I connect into my db then
Show error details
How to fix it?
I had the same issue and was able to fix it by removing the full url (for example: mongodb://myuser:mypassword#mongodb-test.mydomain.com/my_database) in the connection tab and only putting in the mongodb server url: mongodb-test.mydomain.com.
Next, in the Authentication tab, I checked the Perform authentication checkbox, specified the Database, user name, password.
I also added the database in the Advanded tab just in case and I can now connect without error.
Try inserting only e.g: ds12345.mlab.com at address bar instead of full [http:// mongodb://<dbuser>:<dbpassword>#...] and create user to authenticate in mlab.com and then try connect to it. Something like this:
And then:
Whilst this answer is only partly related to the problem, I want to describe the solution in here.
I had this problem when trying to connect via Robo3T to a cluster of MongoDBs hosted on Atlas. They offer a connection string with the protocol in front (e.g. mongodb+srv://<USER>:<PASSWORD>#database-mongodb.net/admin). This was a combination of two problems:
Robo3T does not like the protocol mongodb+srv:// in the URI. You should use only the second part (after the #). Like: database-mongodb.net.
Robo3T does not like shards. At least I could not get to connect with it via that connection string. Fro what I understand, you need that protocol to connect to a shard. Since you can't use that kind of URI, you will need to connect directly to the primary shard. To do that, you need to build a new connection string with the URI of the primary shard. Like this: database-shard-00-00-vemhh.mongodb.net and provide the port to Robo3T. Also, you need to connect via SSL, if you're using MongoDB Atlas (a self-signed certificate configured directly in Robo3T worked for me).
Remove only [http://] worked for me
Get the newer version of the Robo3T client...it can import it automatically from +srv link
I was facing the same problem, but I can solve it by installing Robo 3T 1.3 and import connection details from MongoDB SRV connection string. See this:
Steps to connect remote DB from Robo 3T 1.3
Remember to replace the user in the connection string and the pass at Authentication Tab
The connection string in the picture is dummy by the way

Mongodb: Connection reset by peer

I have a Mongo server running on an Ubuntu box, and I am trying to connect to it with pymongo using the usual syntax:
from pymongo import Connection
c = Connection('db.example.com', 27017)
This works just fine on a recent-model Intel mac (OS 10.6). However, the same code on an older G5 tower (10.5) throws this error:
pymongo.errors.AutoReconnect: [Errno 54] Connection reset by peer
The mongo output on the server reports:
connection accepted from oldmac.example:57681 #3
bad recv() len: 973078528
end connection oldmac.example:57681
I know that I cannot run the mongodb server from the PPC Mac, but it seems odd that I wouldn't be able to connect to the remote database. Or is something else at fault?
Looks like Mike Dirolf already answered your question in the MongoDB Google Group. But for people experiencing the same issue and find themselves on this page, the solution from Mike Dirolf:
Are you using the C extension? (try
pymongo.has_c()). I wouldn't think
that the C extension would even build
on PPC but if it did that is almost
certainly the reason this isn't
working. You can install w/o C with
python setup.py install --no_ext and
then I'd expect things to work.
-- Mike Dirolf
I was able to solve this same issue by using MongoClient instead of the deprecated Connection.
From the Python driver for MongoDB page
Warning DEPRECATED: Connection is deprecated. Please use MongoClient
instead.
For more information, see the new MongoClient documentation for Python.
I was facing the same issue with python3.8, i tried to upgrade and downgrade the pymongo but the result was same Connection reset by peer.
To overcome this problem uninstall the python3.8 and install python3.7 and it work fine. Now i am able to connect to the mongodb and able to perform query.