PP_SS
(Pp Ss)
February 3, 2021, 4:58pm
1
Hi - I am trying to view mongodb collections (just to view) in browser URL by accessing localhost:27017/example.
The mongod server started in cmg prompt.
this is the code writtem:
var db = "mongodb://localhost:27017/example";
mongoose.connect(db, { useNewUrlParser: true, useUnifiedTopology: true });
const conSuccess = mongoose.connection
conSuccess.once('open', _ => {
console.log('Database connected:', db)
})
in the terminal hen I ran it says
“database connected”
when I access the browser localhost as
localhost:27017/example
It looks like you are trying to access MongoDB over HTTP on the native driver port.
please help me how I can view the db collections in browser. Thanks
1 Like
Hi @PP_SS ,
There used to be a brief management http interface but it was removed:
https://docs.mongodb.com/manual/core/security-hardening/#http-status-interface-and-rest-api
To access the database via UI we recommend connecting via compass product:
You can also connect this instance to our Cloud Manager service and use data explorer via the automation agent:
Otherwise a driver or a mongo shell can show collections and query them.
mongo ...
Thanks,
Pavel
PP_SS
(Pp Ss)
February 3, 2021, 5:37pm
3
Hi - Thanks for the quick reply. MongoDb compass is up and running. but not the UI, i am able to access the localhost on example db to view it.
1 Like
@PP_SS , if I understand correctly you are good to go right?
PP_SS
(Pp Ss)
February 3, 2021, 6:00pm
5
I am stuck why is the localhost:27017/example in UI saying still error as
It looks like you are trying to access MongoDB over HTTP on the native driver port.
mongodb compass inside i am able to see the database and its collections
@PP_SS ,
You can’t use localhost:27017/example
as url.
It only works via a MongoDB native driver.
Thanks
Pavel
PP_SS
(Pp Ss)
February 3, 2021, 7:04pm
7
I see that Udemy course that accessed localhost:4000/books but not the localhosst:27017/example
and I accessed like
http://localhost:4000/books it says error
ReferenceError: exec is not defined.
FYI Example is a database and books collection is created in it. in mongodb compas, i am able to access example database and i see books collection in it. not syre why is this error comes. do you have any idea?
They definitely have an application and web server on 4000 port showing web pages.
Its not something coming built-in with MongoDB.
PP_SS
(Pp Ss)
February 3, 2021, 7:59pm
9
I have created that application. after that only i am running the server.
Here is the code:
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
var mongoose = require("mongoose");
var Book = require("./book.model");
var db = "mongodb://localhost:27017/example";
mongoose.connect(db, { useNewUrlParser: true, useUnifiedTopology: true });
const conSuccess = mongoose.connection
conSuccess.once('open', _ => {
console.log('Database connected:', db)
})
conSuccess.on('error', err => {
console.error('connection error:', err)
})
var port = 4000;
//REST get
app.get('/', function(req,res){
res.send("happy to be here");
});
//get all "books" collections
app.get('/books', function(req,res) {
console.log("get all books");
Book.find({})
exec(function(err, books){
if(err){
res.send("error has occured");
} else {
console.log(books);
res.json(books);
}
});
});
app.listen(port, function () {
console.log("app listening on port " + port);
});
and book.model.js code
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var BookSchema = new Schema({
title: String,
author: String,
category: String,
});
module.exports = mongoose.model("book", BookSchema);
PP_SS
(Pp Ss)
February 4, 2021, 3:30pm
10
can anyone please help me?
Could you share a screenshot of the error and status of the MongoDB server on this local host?
PP_SS
(Pp Ss)
February 4, 2021, 6:57pm
12
Sure, I have attached three screenshots onfile saved folders, mongodb server start and url entered port.
Uploading: mongodb-server.PNG… Uploading: mongodb-server.PNG(1)…
PP_SS
(Pp Ss)
February 4, 2021, 7:40pm
13
Sorry that screenshot uploading takes always reading and not able to sent thrid one.
PP_SS
(Pp Ss)
February 4, 2021, 8:42pm
15
this screenshot is server started by entering mongod in cmd propmpt. i have no idea why it is not working in URL.
@PP_SS ,
Error seems to be a js error and not MongoDB related.
Are you sure this mongoose version is compatible with 4.4 MongoDB server?
Thanks
Pavel
PP_SS
(Pp Ss)
February 5, 2021, 5:20pm
17
Thanks for your reply, Pavel. I will check with javascript code again.
I am using mongoose version 5.11.13 is that compatible with 4.4 mongodb server? I will google on it as well. thanks
Hmmm might be A node bug:
opened 08:02PM - 08 Jun 14 UTC
closed 08:08PM - 08 Jun 14 UTC
I have in my gulpfile
``` javascript
/*globals require*/
'use strict';
var gul… p = require('gulp'),
gutil = require('gulp-util'),
minifyCss = require('gulp-minify-css'),
autoPrefixer = require('gulp-autoprefixer'),
notify = require('gulp-notify'),
less = require('gulp-less'),
browserSync = require('browser-sync'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
lessAssetDir = 'app/assets/less',
cssDir = 'public/css';
gulp.src(lessAssetDir + '/styles.less')
.pipe(notify("Found file: <%= file.relative %>!"));
```
and when I run gulp I get
```
/Users/xxx/node_modules/gulp-notify/node_modules/node-notifier/lib/utils.js:14
var notifyApp = exec(shellwords.escape(notifier) + ' ' + options.join(' '),
^
ReferenceError: exec is not defined
at Object.module.exports.command (/Users/xxx/node_modules/gulp-notify/node_modules/node-notifier/lib/utils.js:14:19)
at /Users/xxx/node_modules/gulp-notify/node_modules/node-notifier/lib/notifiers/terminal-notifier.js:38:13
at /Users/xxx/node_modules/gulp-notify/node_modules/node-notifier/lib/utils.js:63:14
at ChildProcess.exithandler (child_process.js:645:7)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:753:16)
at Socket.<anonymous> (child_process.js:966:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:465:12)
```
Package versions
```
$ npm -v
1.4.14
$ node -v
v0.10.28
$ gulp -v
[23:01:33] CLI version 3.7.0
[23:01:33] Local version 3.7.0
gulp-notify@1.3.1
OSX 10.9.3
```
What am I doing wrong?
Please try to update node and npm versions…
Thanks,
Pavel