Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
saludar no es una función (sin embargo, se declaró en el archivo mongoose como un método de esquema) (JS) -

este es el archivo de mangosta que ejecuto a través de Node:

 const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/shopApp') .then(()=>{ console.log('CONNECTION OPEN!!!') }) .catch(err=>{ console.log('HO NO ERROR!!!') console.log(err) }) // alternative syntax for Schema, now we can add additional information. the require. const productSchema = new mongoose.Schema({ name: { type: String, required: true, maxlength: 20 // Schema options }, price: { type: Number, // number character inside a string will be accepted and the opposite also!!!!!!!!!! min: [0, 'Price must be positive'] // minimum character from SchemaTypes options and then error msg }, onSale: { type: Boolean, default: false }, categories: { //[String] which means: it should be an array only consisting of strings type: [String] }, // qty: { online: { type: Number, default: 0 }, inStore: { type: Number, default: 0 } }, size: { type: String, enum: ['S', 'M', 'L'] // can be only one of this values, else it return an error } }) const product = mongoose.model('product', productSchema); //instance methods // someSchema.methods.findSimilarType = function() { //... //} productSchema.methods.greet = function(){ console.log('HELLO!!! HI!!! HOWDY!!!') } // we want to use regular function /*const bike = new product({name: 'Cycling Jersy', price: 18.50, categories: ['Cycling', ' Safety'], size: 'XL'}) // the mongo will ignore the color property bike.save() .then(data=>{ console.log('IT WORKED!') console.log(data) }) .catch(err=>{ console.log('HO NO ERROR!!!') console.log(err) })*/ product.findOneAndUpdate({name: 'Tire pump'}, {price: 1}, {new: true, runValidators: true}) // Schema constraints don't work with updating ( it below minimum price), // you need to set ---> runValidators: true!!!!! .then(data=>{ console.log('IT WORKED!') console.log(data) }) .catch(err=>{ console.log('HO NO ERROR!!!') console.log(err) })

en node.js cargué este archivo mangosta y creé una instancia del modelo e intenté ejecutar la función saludar en él.

 const p = new product({name: 'Big Bag', price: 10}) p.greet()

En segundo plano, mongod y mongo se ejecutan en el aviso.

Recibo un mensaje 'saludar no es una función'.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!