Hey, guys,
I’m trying to look up information in a related document. I have this structure:
{
"_id": "61e16e1edf2e211c5098852f",
"data1": "xxx",
"data2": "xxx",
"data3": "xxx",
"access": {
"_id": "61e16e1edf2e211c5098852d",
"data4": "xxx",
},
I declared the model like this:
const mongoose = require("mongoose");
const Requests = mongoose.model(
"Requests",
new mongoose.Schema({
data1: String,
data2: String,
data3: String,
access:
{
type: mongoose.Schema.Types.ObjectId,
ref: "Access"
}
})
);
module.exports = Requests;
I need to do two filters, the first one searches using “data1” OR the second one using “data4”
I did this method, but I have difficulties accessing the data4. How do I access the data4?
exports.filter = async (req, res) => {
const query = {};
var data = req.body;
if (data.data1) {
query.data1 = data.data1;
}
if (data.data4) {
query.data4 = data.data4;
}
const sol = await Requests.find(query).populate("access");
res.send(sol);
}
When I send data in “data4” I get even though I have results. I appreciate if anyone can help me analyze it.