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

How to populate the nested objects in mongoose?

Issue here’s the booking schema const bookingSchema = new mongoose.Schema({ userId: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true, }, routeId:{ type: mongoose.Schema.Types.ObjectId, ref: "Route", required: true, } }) In this table the routeId(route schema) contains the Bus table(referenced). const routeSchema

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

How can I get data other than 24 Hours in Mongoose

Issue var allData = await Account.find({}) var hoursData = await Account.find({"_time":{ $gt:new Date(Date.now() – 24*60*60 * 1000) }}) var AllData_array = []; allData.forEach(data => { var _WalletAdress = data._WalletAdress; AllData_array.push(_WalletAdress) }); var HoursData_array = []; hoursData.forEach(data => { var _WalletAdress

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

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

Mongoose use of .select() method

Issue I’m pretty confused with the use of the select method. This is how I use it, and it’s wrong: Transaction.find({username : user.username}).select(‘uniqueId’, ‘confirmation_link’, ‘item_name’, ‘timeout’, ‘username’, function(err, txs){ callback(txs); }); What I’m trying to achieve is simply to select

Continue reading