Reputation: 41
I am trying to save an new document record and some of the fields are being omitted and I have not been able to figure out why.
Here I am setting my order object
var obj = new Order(orderObj);
console.log('orderObj', orderObj);
console.log('obj', obj);
output from console.log:
orderObj { customerId: '5806e2a1759fd9ad7a1f60eb',
products:
[ { productId: '5806e7e3d0073cb4d2946aad',
customerPrice: 100,
notes: 'test',
originalPrice: 99.95,
priceOverride: true } ],
notes: 'some optional order notes',
createdBy: 'test',
total: 99.95 }
obj { customerId: 5806e2a1759fd9ad7a1f60eb,
notes: 'some optional order notes',
createdBy: 'test',
_id: 5808171e802121505e33b252,
shipped: false,
shippedDate: 2016-10-20T01:00:14.019Z,
status: 'Created, Not Shipped',
products:
[ { productId: 5806e7e3d0073cb4d2946aad,
_id: 5808171e802121505e33b253,
quantity: 1 } ] }
Here is my schema:
var orderSchema = new mongoose.Schema({
customerId: { type: mongoose.Schema.Types.ObjectId, ref: 'Customer'},
products: [{
productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product'},
quantity: { type: Number, default: 1 },
originalPrice: { Type: Number },
customerPrice: { Type: Number },
priceOverride: { Type: Boolean, default: false },
notes: { Type: String }
}],
notes: String,
status: { type: String, default: "Created, Not Shipped" },
orderDate: { type: Date },
shippedDate: { type: Date, default: Date.now },
shipped: { type: Boolean, default: false },
total: {Type: Number, default: 0.00 },
createdBy: { type: String }
}, schemaOptions);
I cannot figure out why total and product fields (originalPrice, priceOverride) are being dropped from the mongoose Schema instance object.
Upvotes: 0
Views: 2040
Reputation: 97
Also, when sending a request using postman, use content-type as JSON
Otherwise, data in fields will not get stored
Upvotes: 0
Reputation: 348
[this answer is for the record]
I had same kind of problem and in a schema where maxconnections
and roomNo
were not being saved,
I had schema
maxconnections: {type: Number | String },
roomNo: {type: Number | String },
changed it to
maxconnections: {type: Number },
roomNo: {type: String},
and now it works fine (!._.)
Upvotes: 2
Reputation: 41
Of course I figured it out right after I posted this question. The type in the Schema was listed as Type instead of type.
Upvotes: 3