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
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
to mongod...@googlegroups.com
Are you using ObjectId("string") ?
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. 
Take a look at schema design
Reply all
Reply to author
Forward
0 new messages