Finding my ObjectId

16 views
Skip to first unread message

Steffan Perry

unread,
Sep 5, 2012, 11:02:05 AM9/5/12
to mongo...@googlegroups.com
I am trying to pull all my employees with multiple department IDS

Here are my classes:

Class Department
    key :name
end

Class Employee
    key :department_id
    key :name
end

This works:

@employees = Employee.all(:$or => [{:department_id => @department1.id}, {:department_id => @department2.id}])

but this does not:

@employees = Employee.all(:$or => [{:department_id => '4fda36b9b3b5bb062e000183'}, {:department_id => '4fda36b9b3b5bb062e000183'}])

How do i find by the ObjectID if i have the number saved as a string?

Thanks,
Steffan

Jon Kern

unread,
Sep 5, 2012, 7:14:03 PM9/5/12
to mongo...@googlegroups.com
try using $in and give it an array
jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA
Steffan Perry said the following on 9/5/12 11:02 AM:
--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en

Jon Kern

unread,
Sep 5, 2012, 7:21:16 PM9/5/12
to mongo...@googlegroups.com
oh, and you should probably also consider a different design if you want
Employee to be in 1..* Departments. Your current model seems to not
allow that, right?

and you are not using any of the associations available...

maybe there are some helpful modeling and coding tips here for you:
https://github.com/JonKernPA/mongo_examples/tree/master/user_event

jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA

Steffan Perry said the following on 9/5/12 11:02 AM:
Reply all
Reply to author
Forward
0 new messages