简体   繁体   中英

Mongodb doesn't show data

I've created a poject using yeoman and created a data base using mongodb, I have a collection called "Datos", I want to see the elements of my database on the screen, this is my code:

var express = require('express'),
router = express.Router(),
mongoose = require('mongoose'),
datos = mongoose.model('Datos');
module.exports = function(app){
    app.use('/',router);
};
router.get('/BaseDatos',function(req,res,next){
    db.getCollection('Datos').find(function(err,Datos){
        if(err) return next(err);
        res.render('index',{
            titulo:'prueba',
            Datos: Datos
        });
    });
});

I'm using jade to show the data:

extends layout
block content
h2 Sala #{Datos.Nombre}

I don't know what the problem is.

Can you help me please?

The result of calling find is a cursor , not the document results. Call toArray on the cursor to get the documents:

db.getCollection('Datos').find().toArray(function(err,Datos){

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