When adding new entries into mongodb, the ids no longer appear as ObjectId but instead show up as an object.
"_id" : {
"_bsontype" : "ObjectID",
"id" : "U\u0013[-Ф~\u001d$©t",
"generationTime" : 1.43439e+09
}
Anticipated format:
"_id" : ObjectId("55107edd8e21f20000fd79a6")
The version of my mongodb is 3.0.3 and here is the code along with the schema:
var Script = {
run: function() {
return CourseModel.findQ()
.then(function(courses){
return courses.map(worker);
}).catch(function(error){
console.log(error);
});
}
};
function worker(course){
var category = { name: course.name, displayOrder: 0 };
return CategoryModel.createQ(category).then(function() {
course.set('name', undefined);
return course.saveQ();
});
}
module.exports = Script;
var CategorySchema = new Schema({
name: {
type: String,
required: true,
unique: true
},
active: {
type: Boolean,
default: true
},
displayOrder: Number,
updateDate: Date,
subcategories: [{
type: Schema.Types.ObjectId,
ref: 'subcategories'
}]
});