I am trying to find and update a subdoc using mongoose and mongdb but I can't seem to find the subdocs using the ids.
My schema
var Attending = new Schema({
users: []
});
var Query = new Schema({
name: [],
url: [],
attending: [Attending],
img: []
});
Using the ids for both docs, just finding returns null
for the doc. However, if i only using the general Id I can find the entire doc but not the subdoc.
Queries.findOne(
{ "_id": queryId, "attending._id": attendingId },
function(err, doc) {
if (err) throw err;
console.log(doc);
res.render('index');
}
);
sample doc
{
"_id": {
"$oid": "58d995026d7c8f0a3028a50f"
},
"img": [
"https://pic1",
"https://pic2"
],
"attending": [
{
"_id": {
"$oid": "58d995026d7c8f0a3028a505"
},
"users": [
"somebody"
]
},
{
"_id": {
"$oid": "58d995026d7c8f0a3028a506"
},
"users": [
"another person"
]
}
],
"url": [
"https://www.yelp.com/2",
"https://www.yelp.com/1"
],
"name": [
"The Rivermill",
"Sharkeys"
],
"__v": 0
}
I am using the correct ids and expect to the first subdoc in attending to be returned or whichever one is searched. Instead null
is returned.
Queries is made like this:
var names = [];
var urls = [];
var imgUrls = [];
var attendingArray = [];
for (var i=0; i<10; i++) {
names.push(businesses[i].name);
urls.push(businesses[i].url);
imgUrls.push(businesses[i].image_url);
//add attending schema
var newAttending = Attending({
users: ["somebody"]
});
attendingArray.push(newAttending);
}
var newQuery = Queries({
name: names,
url: urls,
attending: attendingArray,
img: imgUrls
});