There was an issue when attempting to execute the mongodb --eval command

Attempting to execute a JavaScript (JS) file in order to obtain configuration server information for a shard. While it runs successfully in the mongo shell, the resulting output is too extensive to analyze through the command prompt. To address this issue, I attempted to save the output to a file using the following command:

F:\git\bits-n-pieces\scripts> mongo --shell wts.js aggutil.js \
--eval "printjson(wts('config192'))" > out.log 
  MongoDB shell version: 2.6.4 connecting to: test 
  type "help" for help 
  2015-02-16T15:48:34.088+0530 
  ReferenceError: wts is not defined

Unfortunately, the attempt to simultaneously load and execute the JS function proved unsuccessful. Is there an alternative method available to execute the JS function and save the output to a file?

Answer №1

Avoid using --shell in combination with the redirection operator > as it will cause the shell to redirect to stdout and may cause the program to hang.

mongo test.js test1.js --eval "var t = 900" > out.txt

Additionally, there seems to be an issue with your JavaScript files as it is indicating that wts is not defined. Make sure you are copying and pasting the command exactly as shown when executing it. When I run a similar command like this:

mongo --shell test.js test1.js --eval "var t = 900" > out.txt

I do not see any output due to the redirection of stdout. However, if I remove the >, I receive the following output:

MongoDB shell version: 2.6.6
connecting to: test
type "help" for help
loading file: test.js
loading file: test1.js
> 

Can you confirm the version of MongoDB shell that you are currently using?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Restrict the size of the chosen array with Mongoose query

Within this document, there is an array stored as a field. The structure is as follows: var UserSchema = new mongoose.Schema({ activities:[{ action:String, time:Number, extraInfo:{} }] }) My goal is to retrieve this array, ...

Stripping away AM | PM from date variables

Is there a way to accurately calculate the difference between two datetime values in minutes without including AM|PM? When attempting to trim out the AM | PM from my code, I encounter errors (specifically NaN minutes). How can I safely remove this element ...

Ways to notify the user about a lost internet connection

Currently, I am working on developing an android application using HTML & JS. After successful development, I plan to use PhoneGap for this project. One of the key features I want to implement is having the app alert the user when their device is not c ...

Encountering issues while attempting to transmit several files to backend in React/NestJS resulting in a BAD REQUEST error

My goal is to allow users to upload both their CV and image at the same time as a feature. However, every time I attempt to send both files simultaneously to the backend, I encounter a Bad Request error 400. I have made various attempts to troubleshoot th ...

A method to use jQuery to replace newlines with commas in user input

Input Processing Challenge <input> Whenever there is multi-line text pasted into the input field, I need to replace newlines (\r, \n, and \r\n) as well as tabs \t with commas ,. This scenario mainly occurs when users copy c ...

Encountering session timeout problem post enabling Httponly and secure attributes in Tomcat configuration file

Upon testing the application on an older version of Firefox (v42) as per requirement, I encountered an issue. I made sure to enable the Httponly and secure attributes in my web.xml file: <session-config> <session-timeout>30</session- ...

Ways to identify when a specific react component has been clicked

Currently working on developing a klondike game with 4 empty stacks at the start of the game. The initial page layout resembles the first image provided in the link. I am facing an issue where I cannot determine which component was clicked when clicking on ...

Troubleshooting: Issue with Angular 2 bidirectional data binding on two input fields

Hi there, I am encountering an issue with the following code snippet: <input type="radio" value="{{commencementDate.value}}" id="bankCommencementDateSelect" formControlName="bankCommencementDate"> <input #commencementDate id="bankCommencementDat ...

React: Displaying a Notification when No Records are Found

I am currently tackling a project in ReactJS where I need to fetch data from a server using an API. I have implemented search filtration, but I would like to display a message when there are no records available. As a beginner in ReactJS, I am seeking as ...

Is there a way to retrieve the current route on a custom 404 page in Next.JS?

I have set up a custom 404 page for my Next.JS application (404.js). I want to display a message stating The route <strong>/not-a-route</strong> does not exist, but when I use Next.js's useRouter() and router.pathname, it incorrectly ident ...

Using AJAX with the GET method, send a form submission to retrieve a response using XMLHTTPRequest

I am working on a form where users can select values from two dropdown menus. The options in the dropdowns are populated dynamically from a JavaScript file, which contains a list of exchange rates. I have written the code to calculate and display the resul ...

What is the best way to use jQuery's $get() function to import a text file from an external website into a JavaScript

Once the button is clicked within the script below, it will load the contents of the file "" and present it on the screen. How should the .get() function syntax be correctly written to fetch data from an external website and place it in #content? <!DO ...

Searching for a specific button within a grid with webdriverIO

I have a grid panel created with ExtJS that contains over 20 rows of data. My goal is to use WebdriverIO as the test driver to search through each row for an icon indicating active mode. How can I write a script that searches each row until it finds the f ...

Modify the variable for each VU in K6 (refresh token)

When I start my K6 test, I utilize my setup() function to obtain a token that will be used by every VU. I want each VU to have the same token, rather than generating individual tokens for each one. Although this works fine initially, the challenge arises ...

Capturing hyperlinks spawned from an ajax call using Jquery

Recently, I have encountered an issue with my jQuery code that is designed to intercept links clicked on a page: $(document).ready(function() { $("a").click(function() { //do something here }); }); The problem arises when c ...

Help! My JavaScript Regex is causing a Maximum call stack size exceeded error

I have a lengthy paragraph that requires word boundary comparisons in order to replace matches with the desired value. The desired values will appear in various different patterns, which is why I must create numerous lines of new RegExp to systematically ...

Introducing unspecified margin above a bootstrap 3 affix/scrollspy component

Check out this link to see the navigation with affix and scrollspy functionality as you scroll down (using bootstrap 3): http://codepen.io/datanity/pen/thnua Adding white space at the top causes the affix/scrollspy to trigger in the wrong location. For e ...

Why are my question documents in MongoDB collection empty when using the save() function in Node.js?

Just starting out with MongoDB and have some basic Node knowledge. I'm following an online tutorial for Node, Express, and MongoDB. Currently, I have code that successfully connects to a remote cluster and inserts a document into a collection. However ...

Encountered an issue while utilizing the repeat function: Uncaught RangeError - Maximum call stack size has been exceeded

Calling all experts! I'm in need of assistance. I encountered an error while using the repeat command. function repeat(s, n, d) { return --n ? s + (d || "") + repeat(s, n, d) : "" + s; } ...

Tips for displaying a specific amount of significant digits in a numerical output

Below is the JSON data that needs to be displayed on a web browser: { "testDoubleArr": [1, 2.0, 3.45], "testStr3": "SHA", "testDouble1": 12.56, "testDouble2": 1.0, "testStr1": "OMG" } When displayed on the browser, it appears in the following f ...