'How to import existing collection from MongoDB and Perform operation it?
I am trying to get Data from my existing collection and perform some operation on it, hear what i tried
//for getting existing data
var Vvin = new mongoose.Schema({});
const VS = mongoose.model('V',Vvin,'vs');
Above code is working but now comes issue
//To perform operation
app.get('/get', (req,res) => {
VS.find({vWebsite : '123'},(error,result) => {
if(error){
res.json(error)
}else{
res.json(result);
}
})
it is returning all data without filtering vWebsite but if i use _id it's work properly
Solution 1:[1]
Try const result = await VS.findOne({vWebsite : '123'});.
Also remember to make your function async.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mkhgkk Lmnx |
