简体   繁体   中英

Collections is showing but documents is not showing in mongoDB

I am new in MEAN web app and I downloaded the dummy project in MEAN, there

sign-up and login. mongoDB connected successfully and I created a collection

user .sign-up and login functionality working well.everything is OK. But I am

confuse about user collection documents. When I sign up definitely data goes to the user collection because login done successfully but when I use this command

                           db.collection.find() 

Nothing result show I created so many account and using them login successfully

And if I use wrong username or password then login not allowed. Please tell me

where is store data in mongoDB. bellow

my app.js file

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var api = require('./routes/api');
var users = require('./routes/users');

// database connectivity
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/ditroapp');
var db = mongoose.connection;

db.on('error', function (err) {
  console.log('mongo connection error', err);
});

db.once('open', function () {
  console.log('mongo connected.');
});

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/api', api);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});


module.exports = app;

I don't know if i have understood your question. In the mongoshell if you want to use a certain db you have to run the command "use name_db" where name_db is the name of the db you created. After that you can show the collections in the selected db with the command "show collections". After that you can find all the document in a collection with the command db.name_collection.find() where nome_collection if the name of the collection you want to retrieve data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM