MongoDB

 MongoDB: MongoDB is a popular NoSQL database that is commonly used with Node.js. It provides a flexible and scalable way to store and retrieve data. Here's an example of how to connect to a MongoDB database and perform some basic operations:

javascript


const mongoose = require('mongoose');


mongoose.connect('mongodb://localhost/myapp', { useNewUrlParser: true, useUnifiedTopology: true });


const UserSchema = new mongoose.Schema({

  name: String,

  email: String,

});


const User = mongoose.model('User', UserSchema);


const user = new User({

  name: 'John Doe',

  email: 'john.doe@example.com',

});


user.save((err, user) => {

  if (err) throw err;


  console.log('User saved successfully');

});

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...