How to generate ObjectId in Python

5,863 views
Skip to first unread message

gau...@serofero.net

unread,
Mar 30, 2015, 9:49:55 AM3/30/15
to mongod...@googlegroups.com
In Node, using mongoose one can:

var mongoose = require('mongoose');
//and
var myObjId = mongoose.Types.ObjectId();                  

How to do something similar in Python? 

I'm using pymongo which is great by the way. 

Thanks.                                                                                           

Will Berkeley

unread,
Mar 30, 2015, 10:44:10 AM3/30/15
to mongod...@googlegroups.com
Use bson.ObjectId from the bson package:

> import bson
> bson.ObjectId()
ObjectId('551960df461a2ea940e51ddb')

-Will

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/283ff34f-c727-478c-830b-d28fc0b2b1b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages