tinycodinglm / sys /sys-0003.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 19)
034ba67 verified
|
Raw History Blame
2.07 kB
deepseek-harness trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

How do I use MongoDB effectively?

Assistant
javascript
// Insert
db.users.insertOne({ name: "Alice", email: "alice@test.com", tags: ["admin"] });
db.users.insertMany([{ name: "Bob" }, { name: "Charlie" }]);

// Query
db.users.find({ age: { $gte: 18 }, tags: "admin" });
db.users.findOne({ _id: ObjectId("...") });
db.users.find({}).sort({ created_at: -1 }).limit(10).skip(20);

// Update
db.users.updateOne({ name: "Alice" }, { $set: { age: 30 }, $push: { tags: "premium" } });
db.users.updateMany({ age: { $lt: 18 } }, { $set: { status: "minor" } });

// Aggregation pipeline
db.orders.aggregate([
  { $match: { status: "completed" } },
  { $group: {
    _id: "$userId",
    totalSpent: { $sum: "$amount" },
    orderCount: { $sum: 1 }
  }},
  { $sort: { totalSpent: -1 } },
  { $limit: 10 }
]);

// Indexes
db.users.createIndex({ email: 1 }, { unique: true });
db.users.createIndex({ "address.city": 1, "address.zip": 1 });

// Text search
db.articles.createIndex({ title: "text", body: "text" });
db.articles.find({ $text: { $search: "mongodb tutorial" } });

// Transactions
const session = client.startSession();
session.withTransaction(async () => {
  await db.accounts.updateOne({ _id: from }, { $inc: { balance: -100 } }, { session });
  await db.accounts.updateOne({ _id: to }, { $inc: { balance: 100 } }, { session });
});