Java Script error persisted in db.system.js.save within MongoDB encountered but remains unresolved

Hello all, I am fairly new to the world of mongoDB and I need some help with performing a search using js stored in mongoDB. Below you will find the javascript code that is stored in my mongoDB database.

When attempting the query below:

db.eval("dc(cough and asthma and cold)");

I encountered the following error message:

{
        "errmsg" : "exception: SyntaxError: Unexpected identifier",
        "code" : 16722,
        "ok" : 0
}

Could someone kindly assist me in resolving the above error? Your assistance is greatly appreciated.

// Saving script to mongoDB for future use
db.system.js.save({
     _id : "countAnd" ,
    value : function(userQuery){


        return userQuery.toLowerCase().split("and").length;
    }
});

//Saving 'dc' function to mongoDB 
db.system.js.save({
    _id : "dc",

    value: function(userQuery){

    var numOfAnds = countAnd(userQuery);


    var uQuery = userQuery.toLowerCase().split("and",numOfAnds);

    var dcResults ="";

        for(var i=0; i<uQuery.length; i++){


                var dcResults =db.records.find({diagnosis:uQuery[i]},{diagnosis:true});



        }

        return dcResults;
    }
});

Answer №1

Always remember to enclose your string in quotes, as shown below:

db.eval("dc('cough and asthma and cold')");

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

Bug Alert: Incompatibility between Angular $resource and PHP causing issues with Update and Delete functionalities

As a newcomer to both AngularJS and PHP, I have been struggling to find comprehensive documentation on using $resource to update records in a database. While I did come across a helpful tutorial here that covers most aspects of $resource usage, I am having ...

Unit testing React Native for inputting text values

I am attempting to append a unit to the value of a textInput: https://i.sstatic.net/EqswS.jpg I have attempted to achieve this with the following code but have not been successful: value = { this.state.totalWeight + " Kgs"} I also tried adding ...

Image does not appear on server side when using FormData for AJAX image upload

I am currently working on an image upload system where the image is uploaded as soon as it is selected in the input[type='file'] element. Despite my efforts, I am facing challenges in transferring the image to the server side. Scenario HTML: & ...

How can I use JavaScript to consistently fetch the CSS-defined percentage setting for padding/margin instead of the pixel size?

How can I retrieve the padding set in CSS for a div with {padding:10% 10px 20% 10px;} using JavaScript, considering that window.getComputedStyle(myelement).getPropertyValue('padding'); returns different results? In Firefox, it shows as "10% 10px ...

Having trouble installing the 'ws' npm package on MacOS Big Sur?

Every time I try to install the websocket package using "npm install ws", I keep getting this error message: npm ERR! code ENOSELF npm ERR! Refusing to install package with name "ws" under a package npm ERR! also called "ws". Did you name your project the ...

Having trouble retrieving the desired information within the JSON format. What exactly is the discrepancy between the two sets of data?

I've researched extensively on similar issues but have not been able to find a solution. My goal is to retrieve the name and value of a coin. The Coinmarketcap API has 2 endpoints. The first endpoint, as indicated in the comment, provides the desired ...

Encountering a 'DiscordAPIError: Unknown interaction' error while attempting to share details about a command

As I work on a slash command to deliver information about a specific command when users type /help, I encountered an error when trying to add multiple commands: E:\v13\node_modules\discord.js\src\rest\RequestHandler.js:298 ...

Arranging different API's in a table in ascending order of price

This task might be a bit confusing, but it should have a straightforward solution. I am working with two API links in JSON format to pull data into a table. Currently, all data from API1 is inserted into the table first, followed by data from API2. Both ...

Displaying an image in AngularJS using a byte array received in the response

Dealing with a service that adds properties to a file and returns it as a byte array in the response. I'm struggling to display it properly since it's in byte form. Attempted converting it to base64 but still showing raw bytes. PNG IHDR&L ...

Specify the variable size in a MySQL query

In the query below, the @commid1 variable is initialized as VARCHAR, but I would like to add more data to it, so I need it to be changed to LONGTEXT. SELECT Ar.Communication_ids into @commid1 FROM View1 AR AR Where LEN(Ar.Communication_ids) > 0 and ar ...

Using jQuery to manipulate text

Can I modify this code to function within "{}" instead of using the .chord tags? (Jquery) //This code transposes chords in a text based on an array var match; var chords = ['C','C#','D','D#','E',&apo ...

Is it possible to enforce strict typing for a property within an object that is declared as type 'any'?

In my code, I am dealing with a parent object of type 'any' that remains constant and cannot be changed. Within this context, I need to define a property for the parent object, but no matter what I try, it always ends up being loosely typed as &a ...

What is the best method for removing node and then reinstalling it using nvm?

In my Mac, I have successfully installed Nodejs, but it was done using the usual method. However, in my new role, I've been asked to utilize NVM for Node installation. Can you guide me on the best approach to uninstall Node and then reinstall it with ...

Tips for incorporating validation/restrictions into react-datepicker

I've been working on implementing restriction and validation in a react-datepicker component. I'm utilizing redux-form for validation and normalization purposes. Issue: I've noticed that neither the normalizing function nor the validation f ...

Creating a new document in Mongoose only if it does not already exist is a common

Currently, I am in the process of developing a basic URL shortener using MongoDB and Node.js. Below is the model I am working with: var urlSchema = new mongoose.Schema({ shortUrl: String, longUrl: String, created: { type: Date, default ...

Extract the height of children from the height of their parent

Hey there! I recently discovered a fantastic plugin that helped me achieve equal heights for all the divs on my website. If you're interested, you can check out the plugin here. $('.item-container').responsiveEqualHeightGrid(); However, I& ...

Having trouble with data not being deleted from Elasticsearch index using mongoosastic?

I am currently using mongoosastic in a MEAN stack application. Everything is functioning properly, except that when I delete a document from MongoDB, it doesn't get removed from the Elasticsearch index. As a result, whenever I perform a search that in ...

Why are my API routes being triggered during the build process of my NextJS project?

My project includes an API route that fetches data from my DataBase. This particular API route is triggered by a CRON job set up in Vercel. After each build of the project, new data gets added to the database. I suspect this might be due to NextJS pre-exe ...

Issue with JQUERY where HTML select element is not visible

$(document).ready(function(){ var selArr = [ {val: 'corsair', text: 'Corsair'}, {val: 'evga', text: 'EVGA'}, {val: 'antec', text: 'Antec'} ]; $('#pSupply& ...

Guide on importing an external JavaScript library in Node.js utilizing a TypeScript declaration file

I am working on a Node.js project using Typescript and I am facing an issue with integrating mime.js (https://github.com/broofa/node-mime). Even though I have a declaration file available (https://github.com/borisyankov/DefinitelyTyped/blob/master/mime/mim ...