Home > Enterprise >  How to filter items by _id in MongoDB?
How to filter items by _id in MongoDB?

Time:10-05

I've made _ids by myself: enter image description here

That function does not work:

router.get('/getCompetitions', (request, response) => {
    competitionTemplateCopy.find({"_id": 1})
    .then(data => response.json(data))
    .catch(error => response.json(error))
});

CodePudding user response:

Try this :

    competitionTemplateCopy.find(_id:1)
    .then(data => response.json(data))
    .catch(error => response.json(error))
});

And you should add _id: { type: Number, }, in your model

  • Related