B
B
baroman4ik2021-11-15 20:52:36
JavaScript
baroman4ik, 2021-11-15 20:52:36

How to find out the correct value of BD.findOne in mongoDB?

there is a function having connection to mongoDB:

const Breed = require('./models/Breed')
...
const addBreed = async (arr, data) => {
  const title = arr[4]
  let writeResult = null
  const isАdded = await Breed.findOne({title})
  console.log(isАdded)
  if (isАdded) writeResult = isАdded._id
  else {
    const breed = new Breed({title})
    writeResult = await breed.save()
  }
  addDog(arr, data, writeResult._id)
}

I noticed that Breed is not updated during the work of the program and I can not correctly do findOne to determine if a similar element was added in this session. tell me how best to get out of the situation (update Breed value). I work through mongus.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question