1

I want to display a document, but the id field is missing, although it's in the database.

Topic.findOne({id: 31}).sort({id: -1}).limit(1)
    .then((topic) => {
      console.log(id); //null
      const newTopic = new Topic({
        id: 32,
        level: level,
        topics: topic,
        phrases: [phrases1, phrases2],
        nouns: [nouns1, nouns2, nouns3],
        verbs: [verbs1, verbs2, verbs3],
        adjectives: [adjectives1, adjectives2, adjectives3],
      });
      newTopic.save();
      res.redirect("/admin/panel")
    });
//console.log output
  {
    _id: new ObjectId("620eb4d998b1747bbe24c672"),
    level: 4,
    topics: 'What is your definition of risk?',
    phrases: [ 'Risk is the...', "Anything that is/isn't..." ],
    nouns: [
      'possibility',
      'change',
      'probability',
      'fear',
      'occurrence',
      'proposition'
    ],
    verbs: [
      'to perceive',
      'to reject',
      'to involve',
      'to ruin',
      'to take',
      'to realize'
    ],
    adjectives: [ 'extraordinary', 'uncertaintly', 'different', 'unfavorable', '' ]
  },

As you can see in the image, "id" is in the document, but not shown in the console.

enter image description here

ruleboy21
  • 5,510
  • 4
  • 17
  • 34
jakobheb
  • 23
  • 4

1 Answers1

0

It's because id is a getter of _id as a string, that's why you can't find it. Check this, it should answer your question: https://stackoverflow.com/a/15724424/4518630

Fadi Hania
  • 705
  • 4
  • 11