skip to Main Content

Basically what I want to do is that I have an ObjectId of a qr. I want to use that ObjectId to find out which qrBlock does it belong. Im leaving my dbmodel here
so you can track easily.

qrRoute.post("/scanQr", (req, res) => {
  let { data } = req.body;
  var id = mongoose.Types.ObjectId(data);
  Qr.findById(id)
    .exec()
    .then((qrr) => {
      QrBlock.find({ qr: { "qr.$": id } }, (qrblck) => {
        console.log(qrblck);
      });

      
    });
});

I tried this code above it didn’t work.

2

Answers


  1. Chosen as BEST ANSWER
    QrBlock.findOne({ qr: { $all: [qrr._id] } })
    

    this worked for me


  2. did you try this way

    qrRoute.post("/scanQr", (req, res) => {
      let { data } = req.body;
      var id = mongoose.Types.ObjectId(data);
      Qr.findById(id)
        .exec()
        .then((qrr) => {
          QrBlock.find({ qr: id }, (qrblck) => {
            console.log(qrblck);
          });
    
          
        });
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search