Skip to content
Back to skills

Mongodb Crud Operations Majiayu000

ASecurity

Master MongoDB CRUD operations, document insertion, querying, updating, and deletion. Learn BSON format, ObjectId, data types, and basic operations. Use when working with documents, collections, and fundamental MongoDB operations.

  • 57 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 17, 2026
databasesjavascriptpythongojavasqlexpresstestingdatabase

Works with

  • cli

Security analysis

A100/100

Scanned October 17, 2026

npx -y skills add diegosouzapw/awesome-omni-skill --skill mongodb-crud-operations-majiayu000 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Mongodb Crud Operations Majiayu000?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Mongodb Crud Operations Majiayu000
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/diegosouzapw-mongodb-crud-operations-majiayu000/badge)](https://www.skillsdirectory.com/skills/diegosouzapw-mongodb-crud-operations-majiayu000)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: mongodb-crud-operations
version: "2.1.0"
description: Master MongoDB CRUD operations, document insertion, querying, updating, and deletion. Learn BSON format, ObjectId, data types, and basic operations. Use when working with documents, collections, and fundamental MongoDB operations.
sasmp_version: "1.3.0"
bonded_agent: 01-mongodb-fundamentals
bond_type: PRIMARY_BOND

# Production-Grade Skill Configuration
capabilities:
  - document-insertion
  - document-querying
  - document-updating
  - document-deletion
  - bulk-operations
  - atomic-operations

input_validation:
  required_context:
    - operation_type
    - collection_name
  optional_context:
    - document_schema
    - write_concern
    - read_preference

output_format:
  code_example: string
  explanation: string
  error_handling: string
  best_practices: array

error_handling:
  common_errors:
    - code: CRUD001
      condition: "Duplicate key error (11000)"
      recovery: "Check unique indexes, use upsert if appropriate"
    - code: CRUD002
      condition: "Document validation failed"
      recovery: "Verify document matches schema validation rules"
    - code: CRUD003
      condition: "Write concern timeout"
      recovery: "Increase wtimeout or reduce write concern level"

prerequisites:
  mongodb_version: "4.0+"
  required_knowledge:
    - mongodb-connection
    - bson-types
  driver_requirements:
    - "MongoDB native driver for your language"

testing:
  unit_test_template: |
    // Test CRUD operation
    const insertResult = await collection.insertOne(doc)
    expect(insertResult.insertedId).toBeDefined()
    const found = await collection.findOne({_id: insertResult.insertedId})
    expect(found).toMatchObject(doc)
---

# MongoDB CRUD Operations

Master fundamental MongoDB Create, Read, Update, Delete operations.

## Quick Start

### Connect to MongoDB
```javascript
const { MongoClient } = require('mongodb');

const client = new MongoClient('mongodb://localhost:27017');
await client.connect();

const db = client.db('myapp');
const users = db.collection('users');
```

### Create Documents
```javascript
// Insert one document
const result = await users.insertOne({
  name: 'John Doe',
  email: 'john@example.com',
  age: 30,
  createdAt: new Date()
});
console.log('Inserted ID:', result.insertedId);

// Insert multiple documents
await users.insertMany([
  { name: 'Alice', email: 'alice@example.com' },
  { name: 'Bob', email: 'bob@example.com' }
]);
```

### Read Documents
```javascript
// Find one document
const user = await users.findOne({ email: 'john@example.com' });

// Find all documents
const allUsers = await users.find({}).toArray();

// Find with filter
const activeUsers = await users.find({ status: 'active' }).toArray();

// Find by ObjectId
const { ObjectId } = require('mongodb');
const user = await users.findOne({ _id: new ObjectId('...') });
```

### Update Documents
```javascript
// Update one document
const result = await users.updateOne(
  { email: 'john@example.com' },
  { $set: { age: 31, updatedAt: new Date() } }
);

// Update multiple documents
await users.updateMany(
  { status: 'inactive' },
  { $set: { lastNotified: new Date() } }
);

// Replace entire document
await users.replaceOne(
  { _id: userId },
  { name: 'New Name', email: 'new@example.com' }
);
```

### Delete Documents
```javascript
// Delete one document
await users.deleteOne({ email: 'john@example.com' });

// Delete multiple documents
await users.deleteMany({ status: 'deleted' });

// Delete all documents (careful!)
await users.deleteMany({});
```

## BSON Data Types

```javascript
// String
{ name: 'John' }

// Number (int32, int64, double)
{ age: 30, price: 19.99 }

// Boolean
{ isActive: true }

// Date
{ createdAt: new Date() }

// Array
{ tags: ['mongodb', 'database', 'nosql'] }

// Object (embedded document)
{ address: { city: 'New York', zip: '10001' } }

// ObjectId (default _id field)
{ _id: ObjectId('507f1f77bcf86cd799439011') }

// Null
{ description: null }

// Binary Data
{ image: Buffer.from('data') }

// Regular Expression
{ email: /.*@example\.com/ }
```

## Key Concepts

- **_id Field**: Automatically generated ObjectId, unique identifier
- **Collections**: Tables equivalent in SQL
- **Documents**: JSON-like records (up to 16MB)
- **Field Names**: Case-sensitive, cannot start with $
- **Operators**: $set, $inc, $push, $pull, $unset, etc.

## Python Example (PyMongo)

```python
from pymongo import MongoClient
from datetime import datetime

client = MongoClient('mongodb://localhost:27017')
db = client['myapp']
users = db['users']

# Insert
result = users.insert_one({
    'name': 'John',
    'email': 'john@example.com',
    'createdAt': datetime.now()
})

# Read
user = users.find_one({'email': 'john@example.com'})

# Update
users.update_one(
    {'_id': result.inserted_id},
    {'$set': {'age': 30}}
)

# Delete
users.delete_one({'_id': result.inserted_id})
```

## Best Practices

✅ Always handle errors with try-catch
✅ Use connection pooling
✅ Close connections properly
✅ Use ObjectId for _id fields
✅ Validate data before insertion
✅ Use appropriate write concerns
✅ Index frequently queried fields
✅ Plan for schema evolution

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.