MongoDB installation link. Another MongoDB installation link.
Below a copy of installation commands for Ubuntu 22.04, not tested.
sudo apt-get install gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
Command to start MongoD (terminal staying open might appear an idea):
sudo mongod --config /etc/mongod.conf
// sudo mongod --config /etc/mongod.conf
// npm install mongoose
// Above command not tested, but from memory.
let mongoose = require("mongoose");
let schema1 = new mongoose.Schema({
valueA: String,
valueB: Buffer,
valueC: Boolean,
valueD: Date,
valueE: Number,
valueF: mongoose.Schema.Types.Mixed,
valueG: mongoose.Schema.Types.ObjectId,
valueH: { type: mongoose.Schema.Types.Array, default: undefined },
valueI: {
valueJ: String,
valueK: Number
},
valueL: { type: String, required: false, default: "defaultstring1" },
valueM: { type: Number, required: true, default: 0 },
valueN: { type: Date, default: Date.now() }
});
let model1 = mongoose.model('schema1', schema1);
mongoose.connect('mongodb://127.0.0.1:27017/2024February28Connection11111111111111');
// https://www.geeksforgeeks.org/mongoose-document-api/
// Code below might not run in sequence. Printing to console should work, wishing. However, the code running order shouldn't go in sequence. For example, code printing might not go in sequence, and multiple runs in terminal might output non-equal results, or different results.
(async () => await model1.insertMany(
[
{valueM: 0},
{valueM: 1},
{valueM: 2},
{valueM: 3},
{valueM: 4},
{valueM: 5},
{},
{},
{},
{},
{}
]))().then(value => {
console.log(value);
(async () => await model1.find())().then(value => {
console.log(value);
(async () => await model1.insertMany(
[
{
valueA: "string0",
valueC: true,
valueE: 1,
valueH: [0,1,2,3,4,5],
valueI: { valueJ: "string1", valueK: 1111 }
},
{
valueA: "string1111",
valueC: false,
valueE: 11111,
valueH: ["arrayvalue0", "arrayvalue1", "arrayvalue2", "arrayvalue3", "arrayvalue4", "arrayvalue5"],
valueI: { valueJ: "string1111111", valueK: 1111111 }
}
]))().then(value => {
console.log(value);
(async () => await model1.find())().then(value => {
console.log(value)
let model1variable1 = new model1(
{
valueA: "model1variable1valueA0",
valueC: false,
valueE: 0,
valueH: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
valueI: { valueJ: "model1variable1ValueJ0", valueK: 1 }
}
);
(async () => await model1variable1.save())().then(value => {
console.log(value);
(async () => await model1.find())().then(value => {
console.log(value);
(async () => await new model1({}).save())().then(value => {
console.log(value);
(async () => await model1.find())().then(value => {
console.log(value);
(async () => await model1.find({valueM: 5}))().then(value => {
console.log(value);
(async () => await model1.find({valueA: "string0"}))().then(value => {
console.log(value);
mongoose.connection.close().then(function() {
console.log('Mongoose default(?) connection closed');
});
}, value => console.log(value));
}, value => console.log(value));
}, value => console.log(value));
}, value => console.log(value));
}, value => console.log(value));
}, value => console.log(value));
}, value => console.log(value));
}, value => console.log(value));
}, value => console.log(value));
}, value => console.log(value));
...by the way, in case want to store data not included in data types above, or data types presented by MongoDB or Mongoose or so on, one idea might go transforming it to a string and storing it as a string.
For example, might transform images to strings and store them as strings.
Strings and numbers might achieve many goals in many cases. Strings might work with text and other data types transformed to strings and transformed back, and numbers might work with mathematics and mathematical work, similar to addition and subtraction and multiplication and division and exponentiation and modulo and so on and so forth... . : )
Also, not sure to have found a way around the promise indentation issue, which, to me, appears similar to callback indentation issues, which promises were about solving, thinking.