Answer the question
In order to leave comments, you need to log in
How to use Mongo DB Atlas to display data on an HTML page using Node JS?
Let's say I have objects in the database with the following structure:
How can I use the database to display information on an HTML page (so that I can access each element of the object separately).
Does anyone know a good video?
I figured out how to create an application for writing to the database, but now I don’t know how to extract data))
Answer the question
In order to leave comments, you need to log in
Hey! I would suggest reading the mongoose documentation . Let me show you how I did it :)
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test', {useNewUrlParser: true, useUnifiedTopology: true});
const carsScheme = new mongoose.Schema({ // описываем схему
title: String, // задаем перечень свойств (Название: тип)
money: Numerable,
descriptions: String,
isVIP: Boolean
});
const cars = mongoose.model('Cars', carsScheme); // Создаем модель по схеме в бд ('Название модели в бд', схема)
var carA = {
title: "Volva",
money: 1000,
descriptions: "...",
isVIP: true
};
var carB = {
title: "Mustang",
money: 3700,
descriptions: "...",
isVIP: false
};
cars.Create([carA, carB]); // Добавляем 2 новых машины
cars.Save(); // Сохраняем
/*
* Получаем тачки
*/
var carVIPS = Tank.find({ isVIP: true }); // Делаем запрос к машинам со статусом "вип"
console.log(carVIPS); // Смотрим результаты
mongoose.close(); // закрываем бд
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question