“Mongoose in NodeM JS” Code-Antworten

Mongoose in NodeM JS

const kittySchema = new mongoose.Schema({
  name: String
});
Good Gemsbok

Mongoose in NodeM JS

await Kitten.find({ name: /^fluff/ });
Good Gemsbok

Mongoose in NodeM JS

const silence = new Kitten({ name: 'Silence' });
console.log(silence.name); // 'Silence'
Good Gemsbok

Mongoose in NodeM JS

const fluffy = new Kitten({ name: 'fluffy' });
fluffy.speak(); // "Meow name is fluffy"
Good Gemsbok

Mongoose in NodeM JS

const kittens = await Kitten.find();
console.log(kittens);
Good Gemsbok

Mongoose in NodeM JS

const Kitten = mongoose.model('Kitten', kittySchema);
Good Gemsbok

Mongoose in NodeM JS

// NOTE: methods must be added to the schema before compiling it with mongoose.model()
kittySchema.methods.speak = function speak() {
  const greeting = this.name
    ? "Meow name is " + this.name
    : "I don't have a name";
  console.log(greeting);
};

const Kitten = mongoose.model('Kitten', kittySchema);
Good Gemsbok

Mongoose in NodeM JS

await fluffy.save();
fluffy.speak();
Good Gemsbok

Ähnliche Antworten wie “Mongoose in NodeM JS”

Fragen ähnlich wie “Mongoose in NodeM JS”

Weitere verwandte Antworten zu “Mongoose in NodeM JS” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen