在mongodb中查找嵌入的文档

时间:2015-04-21 09:37:06

标签: mongodb nosql

这是我的mongo数据库

db.employee.insert(
 {
    _id: 'shop2',
    ShopName: 'Gala',
    ShopAddress: 'Kilmeaden',
    Owner: 'Bryan Power',
    ShopContactNumber: '08766442365',
    Employee: [
                {
                EmployId: '4',
                EmployName: 'Adam Byrne',
                EmployContactNumber: 08688972,
                EmployAddress: 'Bawnfune',
                Salary: 250.00,
                Hours: 25,
                Wage: 9.00,
                EmployeeType: 'FloorStaff'
                },
                {
                EmployId: '5',
                EmployName: 'Shane Power',
                EmployContactNumber: 0873347584,
                EmployAddress: 'Portlaw',
                Salary: 350.00,
                Hours: 32,
                PayType: 'Bank',
                Wage: 8.65,
                EmployeeType: 'FloorStaff'
                },
                {
                EmployId: '6',
                EmployName: 'Jackie Legs',
                EmployContactNumber: 0861231237,
                EmployAddress: 'Ballyduff',
                Salary: 550.00,
                Hours: 32,
                PayType: 'Cheque',
                Wage: 11.60,
                EmployeeType: 'Manager'
                }

]});

我正在尝试访问此insert语句的子文档以检索EmployName,Salary和hours。这是我一直试图做的,但它返回所有三个子文档。我可以隔离这些特定值吗?

db.employee.find({"Employee.EmployId": ""},
     {
      "Employee.EmployName":"Adam Byrne",
      "Employee.Salary": 250.00,
      "Employee.Hours":25
      }).pretty();

0 个答案:

没有答案