2
const cleanMongo = (name) => {
        Item.find({ name: name }, (foundItem) => {
            console.log('found item equals', foundItem)
        });

For some reason, the .log is always says the search returns with null, when it should be returning with a matching document queried successfully only moments before.

ThirdGhostHand
  • 377
  • 5
  • 19
  • 2
    First param is error, so it should be `Item.find({ name: name }, (error, foundItem) => {` – Jack Apr 22 '19 at 18:07
  • 1
    "callback has two parameters - an error object (if an error occured) and a cursor object." https://mongodb.github.io/node-mongodb-native/markdown-docs/queries.html – epascarello Apr 22 '19 at 18:10

2 Answers2

2

First param is error on find's callback, so it should be

Item.find({ name: name }, (error, foundItem) => {
Jack
  • 804
  • 7
  • 18
1

You need to pass the parameters correctly , the error should be the first parameter,

Item.find({ name: name }, (error, foundItem) => {
     console.log('found item equals', foundItem)
});
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396