mongo db with mongoose in node js

technical talkiess
0

 const mongoose = require('mongoose');


main().catch(err => console.log(err));

async function main() {
  await mongoose.connect('mongodb://127.0.0.1:27017/vishalkart');
  console.log("Coneected Bro")
  // use `await mongoose.connect('mongodb://user:password@127.0.0.1:27017/test');` if your database has auth enabled
}

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:- '));
db.once('open', function () {
  console.log("Ayya na bhai")
});


// kiiten scemea.... validation hai iska db me konsa data jayenga ye bata sakte hai
const kittySchema = new mongoose.Schema({
  name: String
});
// adding the new object
kittySchema.methods.speak = function speak() {
  const greeting = this.name
    ? 'Meow name is ' + this.name
    : 'I don\'t have a name';
  console.log(greeting);
};
// schema la lock karayach .... ya nanater chang nahi karu shakat.... kitten ka plural banakar isme store karta hai
const Kitten = mongoose.model('Kitten', kittySchema);
const vishalbuddy = new Kitten({ name: 'vishalBuddy' });
// console.log(vishalbuddy.name);
// vishalbuddy.speak();

vishalbuddy.save();
vishalbuddy.speak();

console.log(Kitten.find({ name: "vishalBuddy"}));

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)