lean query returning full objectid?

214 views
Skip to first unread message

Mongo Rookie

unread,
Nov 7, 2013, 8:41:49 PM11/7/13
to mongoo...@googlegroups.com
I am storing references to other documents in other collections.  I am storing an ObjectId for each of these references.  I.E.

doc = {
  _id: ObjectId(......),
  name: 'something',
  type: 'foo',
  otherThing: ObjectId(.....)
  anotherThing: ObjectId(....)
}

When I get a list of docs back from the database with a lean query the ObjectId's are still ObjectId objects.  However when I format as JSON the turn into strings.  Should a lean query return more of a 'lean' ObjectId?

Jason Crawford

unread,
Nov 7, 2013, 8:45:09 PM11/7/13
to mongoo...@googlegroups.com
They're ObjectIds in the Mongo database—that's not something Mongoose adds. I think “lean” just means that Mongoose doesn't add its own wrapper.

When you format as JSON they turn into strings because there's no such thing as an ObjectId in JSON.

Basically, I think this is a difference between what types MongoDB supports and what JSON supports; they're not exactly the same.

Hope that helps,
Jason

--
Blog: http://blog.jasoncrawford.org  |  Twitter: @jasoncrawford




--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages