Có, có thể gán tên collection vào biến JavaScript. Tạo collection:
> db.employeeInformation.insertOne({"EmployeeName":"John Smith","EmployeeAge":24,"EmployeeSalary":450000});
{ "acknowledged" : true, "insertedId" : ObjectId("5cc6d06baf8e7a4ca6b2ad97") }
Hiển thị document:
> db.employeeInformation.find();
Kết quả:
{ "_id" : ObjectId("5cc6d06baf8e7a4ca6b2ad97"), "EmployeeName" : "John Smith", "EmployeeAge" : 24, "EmployeeSalary" : 450000 }
Trường hợp 1: Gán collection vào biến status:
> var status=db.employeeInformation; > status.find();
Trường hợp 2: Gán vào biến employeeDetails:
> var employeeDetails=db.employeeInformation; > employeeDetails.find().pretty();
Cả hai đều trả về cùng kết quả.