How to use mongoose to read an existing database

in mongoose, you need to define schema, to insert a database. Here is a problem: how do I read a value that is not a table I created? here is the code

related codes

/ / Please paste the code text below (do not replace the code with pictures)

   

what result do you expect? What is the error message actually seen?

found that the output content content is the same, all baidus this table data, ask why this is it!

Jun.22,2021

you need to refer to the field types in the (document) of the document to be read. For example, I want to read the users document. The format of the document is as follows:

here is the reference code:

var mongoose = require('mongoose')
mongoose.connect('mongodb://localhost:27017/demodb')

var db = mongoose.connection;
db.on('error', function(error) {
  console.log(error);
});

// schema
var users = new mongoose.Schema({
  name: {type : String, default : 'foo'},
  password: String
});
mongoose.model('User', users);

// 
var User = mongoose.model('User');
User.find((err, users) => {
  console.log(users)
  db.close()
});
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf7eb5-320c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf7eb5-320c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?