mongosh: how to connect with uuidRepresentation=javaLegacy? - mongodb

I am connecting to my local host mongodb via moongo shell with the following command and getting the following error.
Command
mongosh "mongodb://username:password#localhost:27017/authDb?uuidRepresentation=javaLegacy"
Error
Connecting to: mongodb://<credentials>#localhost:27017/authDb?uuidRepresentation=javaLegacy&directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.2.3
MongoParseError: option uuidrepresentation is not supported
My requirement is to execute mongo queries that involves Java Legacy UUIDs and the expect the query results to be represented like that.
I can achieve this via tools like Robo3T though.
But I am a specific case where I must do it via mongo shell.
I cannot find any support for this elsewhere.

Related

Connect to Database directly via Mongo Compass

Via shell, I can directly connect to mongo database with this string
mongo --ssl host1,host2:port/MyDataBase...
And I land directly on the MyDataBase.
Is there a similar way to do it in Compass? I get connected to whole server and I can see all the other databases. I just want to connect to MyDataBase.
I am using the lattest version of Compass, so it may differ from your current version.
It is important the you are in the network of the server, or use a VPN connection, otherwise, it does not work.
Step 1
Step 2
Please,let me know if that works!

mongorestore from MongoDB to DocumentDB

I am trying to run mongorestore.exe from a DB dump files of collections into DocumentDB database. I have experience with MongoDB and Azure but not much with DocumentDB.
I am getting an error
error parsing command line options: unknown option "ssl"
if I use the command from this tutorial.
I have locally installed MongoDB Community Server, "Windows Server 2008 R2 64-bit and later, with SSL support x64" of the latest stable version - 3.2.4.
It looks like the the --ssl command might not be available since the version 3 (link).
However SSL is enforced by DocumentDB.
Any idea how to migrate an existing database from MongoDB to DocumentDB?The DB is quite large (~GB), hence mongoimport would take too long, we need to user mongorestore, I believe.
Updated, command example:
mongorestore.exe --host myhost123.documents.azure.com:10250 -u myhost123 -p somepassword== --db myhost123 --ssl --sslAllowInvalidCertificates
gives me this error:
error parsing command line options: unknown option "ssl"
If I remove the two ssl options (--ssl --sslAllowInvalidCertificates) I get back an error which kind of makes sense as SSL is enforced on Azure DocumentDB:
Failed: error connecting to db server: no reachable servers
According to your description, I installed MongoDB Community Server Windows Server 2008 R2 64-bit and later, with SSL support x64 -3.4.3 and followed this official tutorial about importing data to API for MongoDB with mongorestore. After some trials, I could restore my local file generated by mongodump to my Azure DocumentDB (MongoDB API) as follows:
Failed: error connecting to db server: no reachable servers
I also encountered this error, and found that it was caused by IP Access Control,
my current IP is not included as the allowed list of client IP addresses. You could find more details about DocumentDB firewall here.

ReferenceError: require is not defined in MongoDB shell

I try to connect MongoDB from Mongo client on windows command (Window 8.1). When I use require() in javascript, I have error as below. Does any one has same issue? Did I miss any require related npm installation? How can't MongoDB shell find require function?
C:\tutorial\nodeMongoAngular-master\lesson2>mongo
MongoDB shell version: 3.0.1
connecting to: test
var MongoClient = require('mongodb').MongoClient;
2015-04-30T14:33:25.812-0400 E QUERY ReferenceError: require is not defined
at (shell):1:19
You are confusing the mongo administrative shell with the Node.js driver. While both environments happen to use JavaScript, the mongo shell has more limited I/O support and is not intended to be used as a driver for application development.
If you want to write Node.js applications using the MongoDB driver (as per your example code), you need to use the node interpreter. The Node.js driver documentation includes a Quickstart tutorial with examples that should help you get started.
#Scott Lee: if you're still looking for an answer, try running with command "node yourscript.js". Make sure mongod is running. 'mongo script.js' will work for pure mongo scripts without nodejs code.

how can I connect to a remote mongo server from Mac OS terminal

I would like to drop into the mongo shell in the terminal on my MacBook. However, I'm interested in connecting to a Mongo instance that is running in the cloud (compose.io instance via Heroku addon). I have the name, password, host, port, and database name from the MongoDB URI:
mongodb://username:password#somewhere.mongolayer.com:10011/my_database
I have installed mongodb on my MacBook using Homebrew not because I want Mongo running on my Mac, but just to get access to the mongo shell program in order to connect to this remote database.
However, I can't find the right command to get me the full shell access I would like. Using instructions found here http://docs.mongodb.org/manual/reference/program/mongo/ (search for "remote") I am able to get what looks like a connection, but without giving my username or password I am not fully connected. Running db.auth(username, password) returns 1 (as opposed to "auth fails" when I provide incorrect username and password), but I continue to get an "unauthorized" error message when issuing the show dbs command.
You are probably connecting fine but don't have sufficient privileges to run show dbs.
You don't need to run the db.auth if you pass the auth in the command line:
mongo somewhere.mongolayer.com:10011/my_database -u username -p password
Once you connect are you able to see collections?
> show collections
If so all is well and you just don't have admin privileges to the database and can't run the show dbs
With Mongo 3.2 and higher just use your connection string as is:
mongo mongodb://username:password#somewhere.mongolayer.com:10011/my_database
Another way to do this is:
mongo mongodb://mongoDbIPorDomain:port

Connecting to Remote MongoDB Server with Python

I have a script that I wrote to query mongodb in python I am using PyMongo. I am trying to use this script to connect to a remote MongoDB server and then run the query within the script and then I want to be able to dump the data I get back from the mongodb into a file.
What are the parameters I need to have at the top of the script to connect to this database, use my username and password, switch to the correct database and then run the query?
Couple of options.
First you could provide a MongoDB URI which can be provided to the MongoClient as an argument. Then you can switch as needed using the standard methods for getting a database once connected.
Alternately, you can connect as normal, use the getting a database once connected method to get the desired database and then use the authenticate function to authenticate against the database.