@karuga/mingodb
v0.1.1
Published
tiny partial implementation of MongoDB
Downloads
3
Readme
MingoDB
MingoDB is a tiny implementation of some parts of the MongoDB shell. It is intended for learning MongoDB concepts without having to install it.
functionality
opening a database connection:
const mingodb = require("@karuga/mingodb");
const db = mingodb("data.json");
create
creating entries in a collection:
db.countries.insertOne({ name: "Argentina", continent: "South America" });
db.countries.insertOne({ name: "Brazil", continent: "South America" });
creating multiple entries at once:
db.countries.insertMany([
{ name: "Finland", continent: "Europe" },
{ name: "Greece", continent: "Europe" }
]);
read
reading an array of all entries:
const allCountries = db.countries.find({});
reading an array of some entries:
const europeanCountries = db.countries.find({ continent: "Europe" });
reading a single entry:
const greece = db.countries.findOne({ name: "Greece" });
update
replacing an entry:
db.countries.updateOne(
{ name: "Argentina" },
{ name: "Argentina", population: 44 }
);
changing an entry:
db.countries.updateOne({ name: "Brazil" }, { $set: { capital: "Brasilia" } });
delete
deleting an entry:
db.countries.deleteOne({ name: "Finland" });
deleting all entries:
db.countries.deleteMany({});