0

I am implementing a web app using MEAN Stack with Angular 6. There I want to save names. In my current application 'A' and 'a' save as two different names. I want to identify 'A' and 'a' as one value when finding and saving in database. Following is my corresponding routes.

/* SAVE Practice. */
router.post("/save", function (req, res) {
  var mod = new practice(req.body);
  practice.findOneAndUpdate({
    practiceName: req.body.practiceName

  },

    req.body,
    {
      upsert: true, new: true
    },

    function (err, data) {
      if (err) {
        res.send(err);
      } else {
        res.send(mod);

      }
    });
});

This is the corresponding method in .ts file.

save(practice: NgForm) {
    if (practice.value.practiceName != "" && practice.value != null) {
      this.practiceService.savePractice(practice.value).subscribe(res => {
        this.getPractices();
      }, (err) => {
        console.log(err);
      });
    }
  }

Does anyone knows a method to achieve case insensitivity in MongoDB ?

RMD
  • 311
  • 1
  • 7
  • 22
  • in your find and update query could you try ,using regex tofind the document – ravi Nov 07 '18 at 05:27
  • I want to save different names given by the user. So I think I cannot use regex. – RMD Nov 07 '18 at 05:30
  • https://stackoverflow.com/questions/1863399/mongodb-is-it-possible-to-make-a-case-insensitive-query please take a look at it, might help using $options:'i'" – ravi Nov 07 '18 at 05:33

0 Answers0