Mongodb alias issues

Hi !
I am new to mongoDB, I have a doubt regarding alias
I want to get custom id name without aggregation
(select id as userId from users)
I am using 4.0 version someone please help me

Hi @Ganesh_ND

Welcome to MongoDB community and good luck on your MongoDB journey.

You don’t need aggregation to do that and a simple project clause in a find or findOne query will do the trick.

db.users.findOne({},{ userId : "$id"});


thanks for response @Pavel_Duchovny :slightly_smiling_face:
this query(db.users.findOne({},{ userId : “$id”})) works in 4.4 but I am using 4.0

Yea in this version its better to use $project with aggregation…