Questions tagged [mongoose-models]

Mongoose Models are constructors compiled from Schema definitions. They are responsible to creating and editing documents from MongoDB.

50 questions
1
vote
2 answers

Is there any other method for deleting a data in mongoose after a given time

const notificationSchema = mongoose.Schema({ type:{ type: String }, message:{ type: String }, userId:{ type: String, required: true, }, timestamp:{ type: Date, default: new…
1
vote
0 answers

Error in using Map scheme type in mongoose

I had defined my mongoose schema like this export const DIDSchema: mongoose.Schema = new Schema({ socialMediaHandles: { type: Map, of: String } }); but when I try to compile the code, I am getting error like TypeError:…
1
vote
1 answer

Mongoose Model.findOne not a function

Having an issue with a model. Trying to do a model.findOne(), but I keep getting the error TypeError: User.findOne is not a function I have the model setup like so: const mongoose = require("mongoose"); const Schema = mongoose.Schema; const…
Chris Rutherford
  • 1,592
  • 3
  • 22
  • 58
1
vote
1 answer

Mongoose: set single option in Model.remove()

Documentation says about Model::remove() method: Removes all documents that match conditions from the collection. To remove just the first document that matches conditions, set the single option to true. The question is how to set this…
Boolean_Type
  • 1,146
  • 3
  • 13
  • 40
1
vote
1 answer

Mongoose model data not updating in mongodb

I'm a newbie in to node.js and mongodb. Im using express for rest-api. I'm trying to create an API where user can post and like. I'm able to create post API and the issue is with like API where the user can click the like button and it will be…
1
vote
1 answer

Get (associative) array of Mongoose models

You can retrieve a Mongoose model like so: let User = mongoose.model('User'); I am looking to do get an associative array of these models. Is there some clever way of getting a list of models using object destructuring? Something like: const {User,…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
0
votes
0 answers

Nest js Circular Dependency & Mongoose Model imports

@Injectable() export class ItemService { constructor( @InjectModel(Item.name) private itemModel: Model, @Inject(REQUEST) private readonly request: Request, @Inject(forwardRef(() => KitchenService)) private…
DhodRaj S
  • 1
  • 1
0
votes
0 answers

How to save Weekly Weather Forecast data in MongoDB using the Mongoose model with weather API?

How to save Weekly Weather Forecast data in MongoDB using the Mongoose model? I'm a beginner and as my first mini-project, I'm writing an app for getting weekly weather forecast data from OpenWeatherApi. The issue I'm facing is that the Api I'm…
Mahsa
  • 1
  • 3
0
votes
2 answers

MongooseError: Model.findOne() no longer accepts a callback && userSchema.plugin(autoIncrement.plugin, 'user');

import mongoose from "mongoose"; import autoIncrement from "mongoose-auto-increment"; const userSchema = mongoose.Schema({ name: String, username: String, email: String, phone:…
0
votes
1 answer

MongoDB/mongoose schema-model behaviours return undefined

In my mongodb/mongoose schema model, I set a user roles document entry like: const mongoose = require('mongoose') const {Schema} = mongoose const userSchema = new Schema({ username: {type: String, required: true}, password: {type: String,…
0
votes
0 answers

Mongoose - Model.create() wrong result for many inserts

I have two models: Question and Answer. when an answer document is created, its reference question document's answerCount field increase by 1. question model: title: { type: String, required: true, unique: true, }, content: { …
0
votes
0 answers

How create multiple unknow dynamic fields for AdminBro + Mongoose

How to create fields for filling in admin-bro when editing a record with dynamic key names that were not originally specified in the mongoose model schema, for further possible editing of these fields through the admin-bro interface ? Model…
0
votes
1 answer

Mongoose, Model.insertMany, TypeError: Cannot read properties of undefined (reading 'length')?

ErrorI used mongodb to create a database, when I use data1.save() then works, but when I used insertMany to save many it didn't work. It gives me this error: TypeError: Cannot read properties of undefined (reading 'length'), does anyone know what…
0
votes
2 answers

I have problem structuring mongoose methods

I am having a problem using callback function in mongoose. Client.findOne({remarks}, (error, docs) => { if(error){ //logging error to DB return next(error) } if(docs){ return…
0
votes
0 answers

Why does it use mongoose.model twice?

I am reading a code that makes me confused! This is the code: import mongoose from 'mongoose'; import { Password } from '../services/password'; // An interface that describes the properties // that are requried to create a new User interface…