error retrieving records using object id , error : INVALID OBJECT ID
112 views
Skip to first unread message
bhaskar rao
unread,
Apr 17, 2012, 12:13:07 AM4/17/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
Hai , lets say i have two collections users and colleges
users collection have
_id , username .
I want to add some users to colleges collection .
Should i add _id or username or some normal id(that increments when
inserted new row) to the colleges collection for reference .What gives
BETTER PERFORMANCE ?
I heard that _id (object id) gives better performance .
So i tried using that .
But when i tried to retrive records using _id like this :
Model.find({ _id : "idstring" })
it is giving error "invalid object id"
i am not getting error when retrieving using others like username
Whats the solution ?
Thanks .
gregor
unread,
Apr 17, 2012, 3:48:28 AM4/17/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
Using the _id as a reference in your colleges collection will give better performance than your own counter but also you could consider embedding some of the user data in the college document - mongo is not a denormalized db and so supports this.