У меня есть тестовый веб-сайт, работающий на localhost: 3000 с локальным mon go db. Он работал нормально, когда внезапно я больше не мог получить документы из базы данных для отображения на веб-сайте. Уже работает куча вещей, которые я перечислю вначале:
- Я установил mon go, mon goose и все другие необходимые пакеты как глобально, так и сохраненные в пакете. json (возможно, было обновление одного из пакетов, и теперь локальная и глобальная версии не совпадают?).
- База данных существует (на / data) и содержит документы, которые я могу найти, когда я запустите 'mon go' в моем терминале.
- Соединение работает как в файле app. js (код ниже), так и без ошибок при запуске 'mongod'.
- Я даже попробовал это с новой базой данных, содержащей новую коллекцию и для которой я сделал тестовую страницу, которая должна отображать файлы. Это код, который я показываю, поскольку он намного проще, чем мой веб-сайт с несколькими страницами (и множеством узлов). Этот тестовый веб-сайт также не работает.
- Я использую E JS для отображения javascript на веб-сайте, но это не похоже на проблему.
Меня чертовски разочаровывает!
Теперь немного кода:
ТЕСТ ПРИЛОЖЕНИЕ. JS
const express = require('express');
const app = express();
const mongo = require('mongo');
const mongoose = require('mongoose');
const path = require('path');
const bodyParser = require('body-parser');
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
mongoose.connect('mongodb://localhost:27017/ScaryMovieNight', {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
},
function(err) {
if (err) {
console.log(err);
} else {
console.info('connection ok');
}
});
let Schema = mongoose.Schema;
let testSchema = new Schema ({
title: String
});
let Test = mongoose.model('test', testSchema);
app.get('/test', (req, res) => {
Test.find()
.then(picture => {
res.render('test', {movies: picture})
// Also tried res.json(picture) which returns an empty object
})
.catch(err => {
console.log(err)
})
});
app.listen(3000, () => {
console.log('Test is working on port 3000.')
});
ТЕСТОВАЯ СТРАНИЦА
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
This is test.
<li>
<% movies.forEach(picture => { %>
<ul>Test Title Is : <%= picture.title %></ul>
<% }) %>
</li>
</body>
</html>
MON GO DB В ОБОЛОЧКЕ
> show dbs
ScaryMovieNight 0.000GB
admin 0.000GB
config 0.000GB
local 0.000GB
> use ScaryMovieNight
switched to db ScaryMovieNight
> db.movies.find()
{ "_id" : ObjectId("5ee0958d569eb17e88a8c2aa"), "title" : "Evil Dead 2", "__v" : 0 }
{ "_id" : ObjectId("5ee177496a0f9090f811be71"), "title" : "Green Room", "__v" : 0 }
{ "_id" : ObjectId("5ee26794d27e52a16c3ab910"), "title" : "Alien", "__v" : 0 }
{ "_id" : ObjectId("5ee7fee3f1a65aac3aa87dcb"), "title" : "Aliens" }
ПОДКЛЮЧЕНИЕ MONGOD
Macintosh-14:TestDB dariustimmer$ mongod
2020-06-19T00:30:50.643+0200 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-06-19T00:30:50.683+0200 W ASIO [main] No TransportLayer configured during NetworkInterface startup
2020-06-19T00:30:50.688+0200 I CONTROL [initandlisten] MongoDB starting : pid=8121 port=27017 dbpath=/data/db 64-bit host=Macintosh-14.local
2020-06-19T00:30:50.688+0200 I CONTROL [initandlisten] db version v4.2.7
2020-06-19T00:30:50.688+0200 I CONTROL [initandlisten] git version: 51d9fe12b5d19720e72dcd7db0f2f17dd9a19212
2020-06-19T00:30:50.688+0200 I CONTROL [initandlisten] allocator: system
2020-06-19T00:30:50.688+0200 I CONTROL [initandlisten] modules: none
2020-06-19T00:30:50.688+0200 I CONTROL [initandlisten] build environment:
2020-06-19T00:30:50.688+0200 I CONTROL [initandlisten] distarch: x86_64
2020-06-19T00:30:50.688+0200 I CONTROL [initandlisten] target_arch: x86_64
2020-06-19T00:30:50.688+0200 I CONTROL [initandlisten] options: {}
2020-06-19T00:30:50.689+0200 I STORAGE [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2020-06-19T00:30:50.690+0200 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
2020-06-19T00:30:51.986+0200 I STORAGE [initandlisten] WiredTiger message [1592519451:986196][8121:0x7fffa59013c0], txn-recover: Recovering log 11 through 12
2020-06-19T00:30:52.254+0200 I STORAGE [initandlisten] WiredTiger message [1592519452:254712][8121:0x7fffa59013c0], txn-recover: Recovering log 12 through 12
2020-06-19T00:30:52.506+0200 I STORAGE [initandlisten] WiredTiger message [1592519452:506030][8121:0x7fffa59013c0], txn-recover: Main recovery loop: starting at 11/42368 to 12/256
2020-06-19T00:30:52.635+0200 I STORAGE [initandlisten] WiredTiger message [1592519452:635022][8121:0x7fffa59013c0], txn-recover: Recovering log 11 through 12
2020-06-19T00:30:52.797+0200 I STORAGE [initandlisten] WiredTiger message [1592519452:797815][8121:0x7fffa59013c0], txn-recover: Recovering log 12 through 12
2020-06-19T00:30:52.854+0200 I STORAGE [initandlisten] WiredTiger message [1592519452:854550][8121:0x7fffa59013c0], txn-recover: Set global recovery timestamp: (0, 0)
2020-06-19T00:30:53.496+0200 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2020-06-19T00:30:53.506+0200 I STORAGE [initandlisten] Timestamp monitor starting
2020-06-19T00:30:53.509+0200 I CONTROL [initandlisten]
2020-06-19T00:30:53.509+0200 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-06-19T00:30:53.509+0200 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-06-19T00:30:53.510+0200 I CONTROL [initandlisten]
2020-06-19T00:30:53.510+0200 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2020-06-19T00:30:53.510+0200 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2020-06-19T00:30:53.510+0200 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2020-06-19T00:30:53.510+0200 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2020-06-19T00:30:53.510+0200 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2020-06-19T00:30:53.510+0200 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2020-06-19T00:30:53.510+0200 I CONTROL [initandlisten]
2020-06-19T00:30:53.520+0200 I SHARDING [initandlisten] Marking collection local.system.replset as collection version: <unsharded>
2020-06-19T00:30:53.522+0200 I STORAGE [initandlisten] Flow Control is enabled on this deployment.
2020-06-19T00:30:53.522+0200 I SHARDING [initandlisten] Marking collection admin.system.roles as collection version: <unsharded>
2020-06-19T00:30:53.522+0200 I SHARDING [initandlisten] Marking collection admin.system.version as collection version: <unsharded>
2020-06-19T00:30:53.525+0200 I SHARDING [initandlisten] Marking collection local.startup_log as collection version: <unsharded>
2020-06-19T00:30:53.525+0200 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2020-06-19T00:30:53.526+0200 I SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version: <unsharded>
2020-06-19T00:30:53.527+0200 I NETWORK [listener] Listening on /tmp/mongodb-27017.sock
2020-06-19T00:30:53.527+0200 I NETWORK [listener] Listening on 127.0.0.1
2020-06-19T00:30:53.527+0200 I NETWORK [listener] waiting for connections on port 27017
2020-06-19T00:30:53.527+0200 I SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version: <unsharded>
2020-06-19T00:30:54.003+0200 I SHARDING [ftdc] Marking collection local.oplog.rs as collection version: <unsharded>
2020-06-19T00:30:57.328+0200 I NETWORK [listener] connection accepted from 127.0.0.1:50163 #1 (1 connection now open)
2020-06-19T00:30:57.329+0200 I NETWORK [conn1] received client metadata from 127.0.0.1:50163 conn1: { driver: { name: "nodejs|Mongoose", version: "3.5.9" }, os: { type: "Darwin", name: "darwin", architecture: "x64", version: "16.7.0" }, platform: "'Node.js v12.18.0, LE (unified)", version: "3.5.9|5.9.19" }
Я пробовал миллион вещей, но, похоже, больше не могу отображать эти заголовки mov ie. Любая помощь будет принята с благодарностью, прошло несколько очень разочаровывающих дней ..