Reputation: 35
I have been beating my head around this code but I am unable to figure out the solution to the problem that I am facing.
I have the following schema for the mongoDb document.
{
"brand" : "String",
"series" : "String",
"model" : "String",
"deviceType" : "String",
"progress" : "Number",
"uploaded" : []
}
Following is the function that i am using for adding the document to the database
var addData = function(details){
console.log(details);
var promise = new Promise(function(resolve, reject){
var document = new Document({
brand : details.brand,
series : details.series,
model : details.model,
devicetype : details.devicetype,
progress : 0,
uploaded : []
});
//save the document into the database
document.save(function(err, document){
if(err){
reject(err);
}
else{
console.log('document added--' + document);
console.log('document should be--' + details);
resolve('Document added successfully');
}
});
})
return promise;
}
The details object that I am using to populate the document is coming out as follows
{ brand: 'HP',
series: 'Elitebook',
model: '8460P',
devicetype: 'laptop',
progress: 0,
uploaded: [] }
But the document that is getting added is not as per the schema and one of the fields is missing in the document. Could some one please tell where I am going wrong. Following is the document that is getting added.
document added--{ __v: 0,
brand: 'HP',
series: 'Elitebook',
model: '8460P',
progress: 0,
_id: 5850f50f0a0d7f055c441b7c,
uploaded: [] }
Upvotes: 0
Views: 111
Reputation: 44999
_id
is the MongoDB ID that is added to every document so that it can be referenced.__v
is added by Mongoose for versioning of the document.devicetype
is not added to the document as it is not in your model. You added deviceType
, not devicetype
. These property names are case-sensitive.Upvotes: 2