Batch process for import - saving output

We have Mongodb and so far so good.
We take extracts from other database’s and import from a Windows server in a batch job.
The problem we are having is that if the import fails then we do not know why.
Running from the command line we can view the output but seems not available in batch.
Anyone else found a way to save the output of Mongodb commands invoked via batch job?

Welcome to the MongoDB Community Forums @Gene_Stigall !

To try to help you we’ll need some more details on your batch import process and the error you are encountering:

  • database import tool & version used
  • error message when your import fails
  • how you are running the batch commands (for example, via a PowerShell script)

Thanks,
Stennie

The version is 4.2.6 and using mongoimport utility.
This is running from a Windows batch file and directing output to a log file (mongoimport.bat > mi.log)
The job failed due to file not being present to import but only the batch file commands in the log file,
not the actually errors which are/were:

2021-07-27T07:07:24.442-0400 Failed: open c:\TEMP\nofile.json: The system cannot find the file specified.
2021-07-27T07:07:24.443-0400 0 document(s) imported successfully. 0 document(s) failed to import.

Does the directory c:\TEMP exists?

How is the file nofile.json being created?

It looks like you wrapped the native tool into the script mongoimport.bat. It would be good to share its content as it may help us find the problem.

The folder c:\temp does exist.
the file nofile.json did not exist (had a space issue during creation)
the batch file mongoimport.bat contains a single line:
mongoimport --uri “mongodb+srv://:@azure.mongodb.net/MyDB” --drop --collection nofile --type JSON --file c:\TEMP\nofile.json

Once you corrected,

does it work?

As an old Unix guy, it always bugs me when c:\temp\ and c:\TEMP\ are used interchangeably.

Yes, after file created it worked.
What I want is to capture the screen output of the mongoimport process from being executed in a batch job the way it displays on the screen when running from the command line.

If Windows output redirection does not work then you may look at the documentation to see if it is possible to do.

I’ll look again… had searched for this but not found a definitive yes/no.

thanks