Mongodb
Mongodb
db.BooksDB.insertOne({
title: "Dead Silence",
author: "S.A. Barnes",
isbn: 1250819997,
price: 13.99,
available: true
})
//insertmany
db.BooksDB.insertMany([{
title: "Dead Silence",
author: "S.A. Barnes",
isbn: 1250819997,
price:erjs 13.99,
available: true},
{title: "Day Zero",
author: "C. Robert Cargill",
isbn: 0062405802,
price: 27.99,
available: true},
{title: "Sea of Rust",
author: "C. Robert Cargill",
isbn: 0062405803,
price: 21.99,
available: false}])
//To retrieve only one record that satisfies specific search criteria, you can use
the findOne() method.
db.BooksDB.findOne({"title":"Dead Silence"})
// updateOne()
// updateMany()
db.BooksDB.updateMany({author:"C. Robert Cargill"}, {$set: {author: "Christopher
Robert Cargill"}})
//deleteOne()
db.BooksDB.deleteOne({name:"Christopher Robert Cargill"})
//deleteMany()
db.BooksDB.deleteMany({author:"Christopher Robert Cargill"})
//checking duplicates
{
"name" : "ksqn291",
"__v" : 0,
"_id" : ObjectId("540f346c3e7fc1054ffa7086"),
"channel" : "Sales"
}
db.collection.aggregate([
{"$group" : { "_id": "$name", "count": { "$sum": 1 } } },
{"$match": {"_id" :{ "$ne" : null } , "count" : {"$gt": 1} } },
{"$project": {"name" : "$_id", "_id" : 0} }
]);
//SELECT * FROM inventory WHERE status = "A" AND ( qty < 30 OR item LIKE "p%")
db.inventory.find({ status: "A", $or: [ { qty: { $lt: 30 } }, { item:
/^p/ } ] }).pretty()