How to get the OID of a Postgres table?

To get a table OID, cast to the object identifier type regclass (while connected to the same DB!). This finds the first table (or view etc.) with the given (unqualified) name along the search_path or raises an exception if not found: SELECT ‘mytbl’::regclass::oid; Schema-qualify the table name to remove the dependency on the search path: … Read more

Is MongoDB _id (ObjectId) generated in an ascending order?

No, there is no guarantee whatsoever. From the official documentation (at the time of the original answer): The relationship between the order of ObjectId values and generation time is not strict within a single second. If multiple systems, or multiple processes or threads on a single system generate values, within a single second; ObjectId values … Read more

Difference between storing an ObjectId and its string form, in MongoDB

I convert to string in code to compare and I ensure that anything that looks like an ObjectId is actually used as a ObjectId. It is good to note that between the ObjectId (http://docs.mongodb.org/manual/reference/object-id/) and it’s hex representation there is in fact 12 bytes of difference, the ObjectId being 12 bytes and it’s hex representation … Read more

How to get the size of single document in Mongodb?

In the previous call of Object.bsonsize(), Mongodb returned the size of the cursor, rather than the document. Correct way is to use this command: Object.bsonsize(db.test.findOne()) With findOne(), you can define your query for a specific document: Object.bsonsize(db.test.findOne({type:”auto”})) This will return the correct size (in bytes) of the particular document.

tech