0
var users = db.users.find({});

User has: _id, name, age.

I am trying to print the users so i can see their data, but when i console.log(users) it prints:

Query {
  _mongooseOptions: {},
  _transforms: [],
  _hooks: Kareem { _pres: Map {}, _posts: Map {} },
  _executionCount: 0,
  mongooseCollection: ...
...

Is is possible any way so i can console something like this: console.log(users[0]).['name'] so i can see the name of the first element in the array of users? I tried to JSON.parse(users) but it raises an error.

2 Answers 2

1

Use await or fn like

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await

db.users.find({},function (err, data) {
        console.log(err,data)
    });
Sign up to request clarification or add additional context in comments.

Comments

0

Try this.

db.users.find({},{name:1},function (err, usersdata) {
    usersdata.forEach(function(user){
        console.log(user.name)
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.