This query never finishes:
const stocks = await mongoose.model("stock").find().exec();
console.log(stocks.length);
This query is executed in < 1 second
const stocks = await mongoose.model("stock").find().select("ticker").exec();
console.log(stocks.length);
I have a lot of data on each stock (10 years of stockdata).
What is mongoose doing? Some validation on each find? Some setting I can use to turn it off?
Or is the only option to use mongodb native?
Update:
Ok So I tried to do it mongo native instead:
console.log("start");
const MongoClient = mongodb.MongoClient;
await MongoClient.connect(connectionMongoUrl, (err, db) => {
if (err != null) {
console.log(err);
return Promise.reject(err);
}
const dbo = db.db("tradestats");
dbo
.collection("stocks")
.find({})
.toArray(async function (err, stocks) {
console.log(stocks.length); // never fires
Same problem! It never finishes. So it's not mongoose then. What can it be? Some memory settings in nodejs or something?
Update2:
Is it bad data model design? Wrong database? Should 10 years of stock prices be put in a separate collection and use reference instead?