Home > Software engineering >  How to save this type of object in Mongodb
How to save this type of object in Mongodb

Time:05-10

enter image description herePlease tell me how to make schema and save API for the following object in MongoDB

Need to save 'btcinr' because this data will come from an API.. { "btcinr": { "base_unit": "btc", "quote_unit": "inr", "low": "2712288.0", "high": "2840292.0", "last": "2738934.0", "type": "SPOT", "open": "2836081", "volume": "85.17037", "sell": "2743398.0", "buy": "2740052.0", "at": 1652080075, "name": "BTC/INR" }, }

CodePudding user response:

use mongoose to make your schema

CodePudding user response:

You can make such a schema in mongoose. Example: const crypto = new mongoose.Schema({ base_unit: String, quote_unit: String, etc... }); and if you 'model' the schema like so: const Crypto = mongoose.model('Crypto', crypto); you can easily store it in your database by Crypto.create({ base_unit: "btc", etc... }); You can find more on that here: https://mongoosejs.com/

Edit: The answer stays the same, just put an object where you need it to be an object along with it's properties, besides that, there is always the LINK. That's all I have to say here, I feel like I shouldn't be giving answers 'on plate'.

  • Related