Unable to fill mongodb document with external api data

Issue I am trying to fill my mongodb document with data from unsplash and randomuser api. const userdata = await axios.get("https://randomuser.me/api/?results=51"); const imagedat = await axios.get( "https://api.unsplash.com/photos/random/?count=51&client_id=GWDzPpjHk743C2QnVBRxu8PtmOI3npF5sePZZ7o0pg4" ); I call both apis for 51 results but after 22 results the

Continue reading

Group documents in two by array field Mongo Aggregation

Issue How do I group the date field one to the next one in each document? { _id: ObjectId(‘…’), date: [ISODate(‘2022-05-27T00:00:00.000+00:00’), ISODate(‘2022-05-28T00:00:00.000+00:00’) …] } The desired document would like this: { _id: ObjectId(‘…’), date1: ISODate(‘2022-05-27T00:00:00.000+00:00’), date2: ISODate(‘2022-05-28T00:00:00.000+00:00′) } Solution Here’s

Continue reading

Mongoose where value in array

Issue I have the below code to return all blogs where the blog author ID is equal to the ID of the first administrator (orgAdmin) in an array: let officialBlogs = await Blog.find().where(‘author.id’).equals(help.orgAdmins[0]); But I can’t work out how to

Continue reading

using ObjectId as a data type

Issue I’m trying to create a schema for an object and I’m using ObjectId as type but he gives me an error const mongoose = require("mongoose"); const permissionsSchema = new mongoose.Schema({ roleId: { type: ObjectId, required: true, }, menuPageId: {

Continue reading

MongoDB showing the schema as undefined

Issue While retrieving documents from database values are shown as undefined in console log. Piece of code that causing that issue. const stockSchema = mongoose.Schema({ rollingStockNumber: String, docs: { naturka: String, address: String, coefficient: String, wheel: String, weight: Number }

Continue reading

Referencing a schema, not a model

Issue I want to reference to a subdocument which is defined as a schema. Here’s the example: exam.model.js: const answerSchema = new mongoose.Schema({ text: String, isCorrect: Boolean, }); const questionSchema = new mongoose.Schema({ text: String, answers: [answerSchema], }); const examSchema

Continue reading

can someone tell me what this error mean?

Issue MongoError: cannot do raw queries on admin in atlas i tried to run : mongoose .connect( ‘mongodb+srv://yonco:mypassword@shop.iujhp.mongodb.net/?retryWrites=true&w=majority’ ) .then(result => { User.findOne().then(user => { if (!user) { const user = new User({ name: ‘yonc’, email: ‘yonc@rest.com’, cart: { items:

Continue reading

edit a product from admin panel of eCommerce website project using nodejs with express.js, hbs and mongodb

Issue edit button <td> <a href="/admin/edit-product/{{this._id}}" class="btn btn-primary">edit</a> </td> router.get of edit product link that i given to the edit button var ProductHelpers = require(‘../helpers/product-helpers’) router.get(‘/edit-product/:id’,async (req,res)=>{ let product=await ProductHelpers.getProductDetails(req.params.id) console.log(product) res.render(‘admin/edit-products’,{product}) }) {{!–here i have rendered edit products page

Continue reading

How to run raw mongoDB commands using mongoose?

Issue I’m able to change the mongodb’s-sort-buffer-size using below command db.adminCommand({setParameter: 1, internalQueryExecMaxBlockingSortBytes: <limit in bytes>}) but, how to run the same command using mongoose library? Solution Try this: YourModel.db.db.admin().command({setParameter: 1, internalQueryExecMaxBlockingSortBytes: <limit in bytes>}, function (err,res) { console.log(res); });

Continue reading

MongooseError: Operation `users.findOne()` buffering timed out after 10000ms

Issue This is my connection file const connectDB = async () =>{ const conn = await new mongoose("mongodb+srv://nikunj:gadia7420@cluster0.94xph.mongodb.net/myFirstDatabase?retryWrites=true&w=majority", { usenewurlparser:true, usecreateindex:true, usefindmodify:true, useunifiedtropology:true, urlencoded:true }) } module.exports = connectDB; this is my models file const userSchema = new mongoose.Schema({ username:{

Continue reading