Sobes.tech
Junior — Middle

Can you explain what CRUD means in the context of working with databases?.

sobes.tech AI

Answer from AI

CRUD is an abbreviation that stands for the four main operations with data in a database:

  • Create — adding new records.
  • Read — retrieving data from the database.
  • Update — modifying existing records.
  • Delete — removing records.

In the context of Node.js and working with databases, CRUD operations are implemented through database queries, for example, using ORM or drivers.

An example in Node.js using MongoDB and the Mongoose library:

// Create
const user = new User({ name: 'Ivan', age: 30 });
await user.save();

// Read
const users = await User.find({ age: { $gt: 18 } });

// Update
await User.updateOne({ name: 'Ivan' }, { age: 31 });

// Delete
await User.deleteOne({ name: 'Ivan' });

CRUD is the basis of interaction with databases in most applications.