If we define the array like array:[value:{type:Double}]
, while saving whole numbers like 1 , 2 ...
the mongoose overrides the data type and saves the datatype as int32 rather than expected, because it is obvious that its datatype is int as double deals with floating point.
If you just want an array of values alone (not object), then you can try this :
Schema :
const Double = require("@mongoosejs/double");
const TestSchema = new mongoose.Schema({
name: { type: String },
array: [Double],
});
Query :
let val = 5;
await Test.updateOne(
{ name: "abc" },
{
$push: {
array: val,
},
}
);
Result :
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…