So im working with nodeJS
and mongoDB
. im having a problem with updating a collection and its been a week since im working on it and it really gives me a headache. so this is my Sample collection
{
"_id": ObjectId('51299sdfasdf') //this is just a sample Id
"names": [
"NameA",
"NameB",
"NameC"
],
"names_id": [
ObjectId('asdfasdf1312'),
ObjectId('12sda123123a'),
ObjectId('asdf1212123a')
],
"user_alias": "SampleA"
}
then here's my script
var mongoose = require('mongoose');
var model = mongoose.model('Sample');
model.update( { _id: req.query._id },
{
$set: {
names: namesArray, //this are set of names ex; ['name1', 'name2']
names_id: namesIdArray //this are set of ids ex: [ ObjectId('sgsdfgsd'), ObjectId('asdfasdfadf')
},
},
function(err, results) {
if(err) res.status(500).send(err);
console.log(results);
}
);
I know I code it right. in the names_id arrays i specify all the object Ids like this mongoose.mongo.ObjectId('id here')
. but it doesn't updating anything. here's the result.
{ ok: 1, nModified: 0, n: 1 }
What's the issue here? is this because of the version? my mongoose
version is 2.15.8
Please help me out! thank you!