2

I am new to mongodb and I am trying to get a Documment from the database and populate some fields this is an example :

var profile = await this.profileModel
  .findById(id)
  .populate({
      path: 'posts',
      populate: {
          path: 'comments',
          populate: [
                  { path: 'author', select: ['_id', 'firstName', 'lastName', 'email', 'image', 'status'] },
                    ],
                },
            })
            .lean();

the problem here is that _id for comments and author are objectId and I want to get their values

how can I achieve this ?

1 Answers1

0
const myObjectIdValue = ObjectId.valueOf();

this method returns the str attribute of the ObjectId : An hexadecimal string representation of the object.

learn more here in the official docs

Ahmed Sbai
  • 10,695
  • 9
  • 19
  • 38