MongoDB can write like this
db.getCollection('users').find({})
Or ..
db.users.find({})
Heredb
What is it and how should it be defined in the code?
In mongoose, it is usually written like this:
var User = require('../models/user')
User.find({})
How should it be defined in mongoosedb
Can also write
db.users.find({})
This way of writing?
(⊙ o ⊙o⊙)… … look at the wood in front of your code.
var mongoose = require('mongoose'); var db = mongoose.connect('mongodb://localhost/tasks');
Such code?
db
In fact, it is a connection instance of mongoose.And yours
User
Is it a Model? Your code should look something like this:var mongoose = require('mongoose'); var db = mongoose.connect('mongodb://localhost/tasks'); var schema = new mongoose.Schema({ name: String, path: String }); module.exports = mongoose.model('User', schema);
So you can use:
User.find({});