My code :
const mongoose = require("mongoose");
async function run() {
await mongoose.connect("mongodb://localhost:27017/test", { useNewUrlParser: true, useUnifiedTopology: true });
const citySchema = new mongoose.Schema({
name: String,
country: String
});
const City = mongoose.model('serverdatas', citySchema);
const docs = await City.find({name: "Paris"});
return docs;
}
var test;
test = run();
console.log(test);
Output :
Promise { <pending> }
So, what i'm trying to do is to assign test
with docs
. I want to assign it to a global variable, not only console.log it. The problem is that when I execute my code, I get a Promise.
I am not a good developper, so I don't know how to get the data out of the Promise, and assign it to test
.