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