I have been working on MongoDB Server 4.4 with Mongoshell, MongoDB Compass , MongoDB Cloud, MongoDB Database tools. Now the current installation is MongoDB Server 5.03. I have been facing some difficulties while working with old version of MongoDB.
Should I have to install MongoDB 5.03 along with Mongoshell, Compass, Cloud snd Database tools ?
Can you provide more details on the difficulties you are encountering (for example, specific error messages or unexpected behaviour)?
For the classic mongo shell you should always install a version matching your server release – there will be a startup warning if a major version mismatch is detected.
The new MongoDB Shell, Compass, and Database Tools are independently versioned from the MongoDB server. I’d recommend installing the latest versions of these tools, particularly if you have upgraded to MongoDB 5.0. Older versions should still be compatible but will be missing support for newer server features.
Thank you for your reply. My MongoDB Server Version installed is 4.4.6 , Mongoshell Version installed is V4.4.6 and Compass Version installed is 1.28.1. Since MongoDB Server and Mongoshell are both having same version , there is no question of mismatch. My MongoDB Tool Version is 100. So, I need to install the latest version of MongoDB Tool.
Now, let me tell you the specific details I am encountering with my old version of MongoDB/ Mongo tools though I am not very sure whether there is any other specific reason behind it.
While I am exporting in csv format using - - fields option and --mongoexport to connect mongod running on local host : 27017, I am getting the output.
But , while I am using a file to specify a fields to export in csv format using – mongoexport to connect mongod runing on local host: 27017, I getting no output.
I am getting the error :" Failed: open fields.txt. The system can not find the file specified."
I shall be pleased if you let me know why it is so.
The --fieldFile option I use to export in csv format is
mongoexport --db=users --collection=contacts --type=csv --fieldFile=fields.txt --out=C:\opt\backups\contacts.csv
The database I created in mongoshell:
use users
db.contacts.insertMany( [
{ name: “Sophie Manroe”, address: “123 Example Road” },
{ name: “Charles Yu”, address: “145 Sample Street” }
] );
I want more clarification from your end. The following command
mongoexport --db=users --collection=contacts --type=csv --out=C:\opt\backups\contacts.csv will give the error message : Failed: CSV mode requires a field list.
Also, the following command
mongoexport --db=users --collection=contacts --type=csv --fieldFile=fields.txt --out=C:\opt\backups\contacts.csv will give error message : Failed: open fields.txt. The system can not find the file specified.
So, to get an output :
name
address
what mongoexport command should we need ? Please clarify.
mongoexport --db=users2 --collection=contacts2 --type=csv --fieldFile=fields.txt “name”, “address” --out=C:\opt\backups\contacts2.csv.
I am getting the following error
error parsing command line options: error parsing positional arguments: provide only one MongoDB connection string. Connection strings must begin with mongodb:// or mongodb+srv:// schemes
name: “Sophie Manroe”, address: “123 Example Road”
Here the field name is name, address. Fields values are : “Sophie Manroe”, “123 Example Road” in one line.
You advise me to add two fields in fields.txt. Does it mean : --fieldFile=fieldstext – fields=“Sophie Manroe”, “123 Example Road”
For CSV exports only, you can also specify the fields in a file containing the line-separated list of fields to export. The file must have only one field per line.
For example, you can specify the name and address fields in a file fields.txt :
As per your advice my collection documents
db.contacts.insertMany([
{ name: “Sophie Manroe” } ,
{ address: " 123 Example Road" }
]);
This document is made as you advised to create field value with the field names , name and address so that there can be only one field value with the field names , name and address.
For csv export , we can use the following command-line
Is the command line of mongoexport to create csv output file correct ?
Or anything else we have to add in between fieldFile=fields.txt and --out=C:\opt\backups\contacts.csv
in the command- line of mongoexport to create csv output file ?
I shall be pleased if you specifically reply with my details collection documents which I mentioned in my post.
Regards ,
Arindam Biswas
Following are the details of my database, collection , field_name.text( field.text), mongoexport command - line option , error along with screen shots.
Database and collection in mongoshell
use customers
switch to customers
show collections
info
db.info.insertMany( [
{ Name: “Aniruddha Ray”, address: " Golf green", ph: 9811111111 },
{ Name: “Rahul Chiudhury”, address: “Golf course”, ph: 7922222222 }
] );
field_name.txt file(field.text)
Name
address
phone
Field directory where I saved field_name.txt file > C:\Users\Arindam PC\Documents\field_name.txt
mongoexport command-line option to get output in csv format
mongoexport - - db=customers - - collection=info - -type=csv - -fieldFile=C:\Users\Arindam PC\Documents\field_name.txt - -out=C:\opt\backups\info.csv
Error: 2021-08-19T14:36:18.090+0530 error parsing command line options: error parsing positional arguments: provide only one MongoDB connection string. Connection strings must begin with mongodb:// or mongodb+srv:// schemes
It is a syntax issue
There are spaces in your command
Put the command in a notepad and remove the spaces before each parameter and run the command again.It will work
I have not used any space in the command while usuing the --mongoexport command in mongo shell. Please see the screen shot. In the forum I use space intentionally to clarify two - - lines. I use --db not - -db in mongo shell.
Why did you advise me to put the command on notepad and remove the spaces before each parameter and run the command again ?
He did because you have an error and we are trying to help you figure out what you do wrong. In this case the error seems to be misleading as it says to specify only 1 connection string. I do not see any on your command. And according to https://docs.mongodb.com/database-tools/mongoexport/ you do not need to specify any when connecting to localhost at the default port. By looking in more details, I see that your --fieldFile argument has a space in it. You should put it in double quotes.
Thanks a lot. Atlast I get the solution. I have been stuck up since long. So many people helped me. Let me thank to all again.
Now, what was the issue with respect to my last posting ? I did not use the double quote (" ") both in field_name.txt file and output file.
–fieldFile=“C:\Users\Arindam PC\Documents\field_name.txt”
–out=“C:\opt\backups\info.csv”
I also attach the screen shot of complete command-line option of mongoexport.
Regarding my last query : Why did you advise me to put the command on notepad and remove the spaces before each parameter and run command again ?
I understand that he was trying to help me to figure out what exactly wrong was. Since, I was confident that the issue was not due to space problem I replied that way. I also attached the screen shot and pointed out to verify whether the same space issue also exists in the screen shot also.