One feature on my website allows users to input a number into the field labeled subNum
in a form. Upon submission of the form, I need to validate whether the entered value already exists within any existing document. This validation process is implemented using javascript/meteor.
The data from the form is structured within an object as follows:
participantObject = {
subNum: parseInt(number)
}
Subsequently, this object is inserted as a document into the Participants
collection.
When the submit button is pressed, it is crucial to verify if the entered number is duplicated (i.e., it matches the value for subNum
in any other document). If such a match is found, the form submission must be prevented and an error message displayed accordingly.
I am attempting to conduct this check using the following code snippet:
var existingSubs = Participants.find(
{subNum: {$eq: participantObject.subNum}}
).count();
console.log(existingSubs);
My intention with the code above is to search for all documents where the value of subNum
equals the user-entered value (participantObject.subNum
), and then log the count of matching documents to the console.
However, upon viewing the console, I encounter the error message stating Unrecognized operator: $eq
.
Could this be indicative of misuse of the equality operator?
Is there possibly a more efficient method to carry out such a validation process?