D
D
DeFaNJI2021-10-26 22:08:22
MongoDB
DeFaNJI, 2021-10-26 22:08:22

floating point number in mongoose & mongodb?

I created a user model for mongodb and ran into a problem

. I tried to create floating point values, set 0 by default, but in the console when creating a user I got:

balance: {
    ref: { type: [Function: Double], default: 0 },
    invest: { type: [Function: Double], default: 0 },
    dep: { type: [Function: Double], default: 0 },
    withdrawn: { type: [Function: Double], default: 0 }
  },


User model code:

const mongoose  = require('mongoose')
require('mongoose-double')(mongoose);
 
const SchemaTypes = mongoose.Schema.Types;
const model = mongoose.model
const Schema = mongoose.Schema

const Users = model('User', new Schema({
    id: Number,
    name: String,

    balance: {type: Object, default: {
        ref: { type: SchemaTypes.Double, default: 0 },
        invest: { type: SchemaTypes.Double, default: 0 },
        dep: { type: SchemaTypes.Double, default: 0 },
        withdrawn: { type: SchemaTypes.Double, default: 0 },
    }},

    ref: { type: Object, default: {
        score: { type: SchemaTypes.Double, default: 0 },
        refferer: Number,
    }},

    case: {type: String, default: ''},
    admin: {type: Boolean, default: false},
    lastEarn: { type: Number, default: Date.now() },
}));


I searched the Internet, but could not find information about this, the Double data type is required

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question