U
U
UNy2018-05-11 02:33:54
MongoDB
UNy, 2018-05-11 02:33:54

Print all values ​​from Mongoose base?

var userScheme = new Schema({
    name: String,
    age: Number
});
var User = mongoose.model("User", userScheme);
var user = new User({
    name: "Bill",
    age: 41
});
user.save(function(err){
     
    mongoose.disconnect();  // отключение от базы данных
    if(err) return console.log(err);
     
    console.log("Сохранен объект", user);
});

After saving to the database, user will be a collection? Get everything out of it db.user.find() ??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gleip, 2018-05-11
@UNy

Yes. Just before db.users.find(), you will need to select the database use "database name". The name of the database is specified in mongoose.connect() ( in the first parameter where is the string with the mongo url ). View all available databases in show databases mong

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question