Mongodb: check equality of values โ€‹โ€‹in any document

I have a form on my site where users can enter a number in the field subNum. When a user submits a form, I want to check if a value already entered as a value exists in any existing document. This is all done in javascript / meteor

All form data is placed in the object as follows:

participantObject = {
  subNum: parseInt(number)
}

This object is then inserted as a document into the collection. Participants

When the submit button is pressed, I need to check if the entered number has been entered (i.e. exists as the value for subNumin any document). If so, deny submitting the form and display an error message

I am trying to check something like this:

var existingSubs = Participants.find(
  {subNum: {$eq: participantObject.subNum}}
).count();

console.log(existingSubs);

, , subNum (participantObject.subNum), , .

, Unrecognized operator: $eq

?

?

+4
1

$eq :

var existingSubs = Participants.find(
    {subNum: participantObject.subNum}
).count();
+5

Source: https://habr.com/ru/post/1627877/


All Articles