Questions tagged [mongoose-models]

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

50 questions
0
votes
0 answers

Delete documents from Collection with limit & skip - MongoDB & Mongoose

Mongoose 6.6.1, MongoDB 6.0.1 Our team uses Mongo/Mongoose every day - but just the basics. I experiment with more advanced features, so I got a reputation as the local "Mongoose Guru" - but in the real world, I'm so not. I clean up our log tables…
ChrisNY
  • 3,917
  • 4
  • 27
  • 31
0
votes
1 answer

Can We import Mongoose schema into another Schemas Object array? and then use refs and Populate, to get data into array?

I am a beginner, Can anyone tell me why we have to need to import the whole schema into a new schema Object as an array? what's that Purpose? pages: [nestedSchema] E.g if I have role_name: { type: String, }, pages: { type:…
0
votes
1 answer

Mongoose: using the Model.create() method and new Model() constructor seem to ignore parameters

I am trying to save a new document to a collection, but rather than taking the parameters from the Model() constructor or Model.create() method, an empty object is created. I am probably doing something wrong or missing a small detail somewhere but…
0
votes
1 answer

Mongoose models not written to mongoose.models object. Problem?

I am building a Nodejs/Mongoose backend and I have one MongoDB Atlas cluster with two databases: A and B. I have connected to database A en B with createConnection(). Like so: const connectDB = (url) => { return mongoose .createConnection(url,…
Coen
  • 15
  • 5
0
votes
2 answers

How to make a model of data in mongoose or mongodb

let say, i have some data that contain state (country), province, and year, and the conditions, i will try to explain with this below: state_a: { province: { name: 'prov_1', conditions: { year: 2019, …
0
votes
1 answer

Typescript interface are not overloading / merging subsequent interface fields

I know that interfaces in typescript allow us to merge different types. When i tried to do so, i am getting error while transpiling the script. Here is my buggy interface export interface StoreConfig extends Document, TimeStamps { type: 'webhook' …
tbhaxor
  • 1,659
  • 2
  • 13
  • 43
0
votes
1 answer

should I create a seperate model (collection) for this?

i am building a small web app with MERN, i have a collection that holds "name, email, password, avatar url, and date" and i am going to add to the users some info like a "bio, hobbies(array), "visited countries(array), and another array" question…
ProMaker Dev
  • 105
  • 1
  • 2
  • 12
0
votes
1 answer

Node.js and Mongoose. Reading from one collection and writing to a different one

I am trying to read from one Mongo collection and then take all that data and save it to a new collection. I am using the same schema, but changing the collection name in two different models : UserInfo.js : const mongoose =…
csean11
  • 13
  • 4
0
votes
1 answer

In mongoose.js, can we search for a model with several search parameters?

Im using the module mongoose.js for my mongodb database. My data base looks like this: { thing1: "thing1", thing2: "thing2" } And I want to search a model with several parameters (thing1 and thing2). I tried this: myModel.findOne({ thing1:…
Zitta
  • 74
  • 7
0
votes
1 answer

Mongoose model save

I noticed a very strange behavior when creating a document export const questionSchema: Schema = new Schema( { questionLevel: { type: Schema.Types.Number, index: true }, …
Ashot
  • 245
  • 6
  • 16
0
votes
1 answer

cannot handle model.save error and return to FE

I'm trying to save an item to DB using Mongoose and return the saved item or the error to the client. When making a postman call with a duplicate document i expect to get an error of duplicated, get to the 'catch' statement and retrieve a 500 status…
0
votes
2 answers

Mongoose populate()

referring to Mongoose url populate example given at https://mongoosejs.com/docs/populate.html#checking-populated , there seems to be a two way relationship between both Schema. What if I only have 1 way relationship for example ( using same schema…
BC2
  • 1,129
  • 1
  • 11
  • 22
0
votes
0 answers

Why is module returning a blank object most of the time?

I am trying to figure out why my module isn't loading properly. It's a mongoose model, but even having it just return a string sometimes returns the empty object, so it seems like it's something to do with node. articles/models/articles.js var…
stackers
  • 2,701
  • 4
  • 34
  • 66
0
votes
1 answer

Artist.findOne is not a function

I am getting the error inside my Electron application when I run this code inside my FindArtist.js file: const Artist = require('../models/artist'); /** * Finds a single artist in the artist collection. * @param {string} _id - The ID of the…
Daniel
  • 14,004
  • 16
  • 96
  • 156
0
votes
0 answers

how to add new attributes to existing json file using mongoose

I have the following model representing the existing json file. Player = config.mongoose.model('Player', { birthday: {type: Date, required: true}, // nationality: {type: String, required: true}, // id: {type: Number,…
RichardB
  • 41
  • 4