longsor di nodem js
const kittySchema = new mongoose.Schema({
name: String
});
Good Gemsbok
const kittySchema = new mongoose.Schema({
name: String
});
await Kitten.find({ name: /^fluff/ });
const silence = new Kitten({ name: 'Silence' });
console.log(silence.name); // 'Silence'
const fluffy = new Kitten({ name: 'fluffy' });
fluffy.speak(); // "Meow name is fluffy"
const kittens = await Kitten.find();
console.log(kittens);
const Kitten = mongoose.model('Kitten', kittySchema);
// 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);
await fluffy.save();
fluffy.speak();