Data

MongoDB Document JSON Example

A real-world JSON example of a MongoDB document — ObjectId, embedded sub-documents, and an array of references. Copy-ready for schema design and seed data in MongoDB collections.

{
  "_id": {
    "$oid": "64f1b2a3c4d5e6f7a8b9c0d1"
  },
  "username": "ravi.mehta",
  "email": "ravi.mehta@example.com",
  "address": {
    "street": "42, Shyamal Cross Road",
    "city": "Ahmedabad",
    "country": "IN"
  },
  "orderIds": [
    {
      "$oid": "64f1b2a3c4d5e6f7a8b9c0d2"
    },
    {
      "$oid": "64f1b2a3c4d5e6f7a8b9c0d3"
    }
  ],
  "tags": [
    "premium",
    "early-adopter"
  ],
  "createdAt": {
    "$date": "2024-03-12T08:45:00.000Z"
  },
  "__v": 0
}

Field Reference

_idrequiredObjectIdMongoDB's default 12-byte primary key, encoding a timestamp, machine identifier, and counter — auto-generated unless you supply your own
addressoptionalobjectAn embedded sub-document — stored inline with the parent, not a separate collection, which is idiomatic MongoDB for one-to-one 'belongs entirely to this document' data
orderIdsoptionalarrayReferences to documents in a separate 'orders' collection by ObjectId — MongoDB's equivalent of a foreign key, resolved manually or via $lookup aggregation
__voptionalnumberMongoose's internal version key used for optimistic concurrency control on array modifications — not part of MongoDB itself, only present when using the Mongoose ODM

Variants

Extended JSON (Canonical)MongoDB's canonical Extended JSON format, used by mongoexport and driver debug output — every BSON type is explicit, unlike the relaxed form shown above.
Extended JSON (Canonical)
{
  "_id": {
    "$oid": "64f1b2a3c4d5e6f7a8b9c0d1"
  },
  "username": "ravi.mehta",
  "balance": {
    "$numberDecimal": "1042.50"
  },
  "loginCount": {
    "$numberLong": "48213"
  },
  "createdAt": {
    "$date": {
      "$numberLong": "1710233100000"
    }
  }
}

Common Use Cases

  • Designing embedded vs. referenced document schemas before writing Mongoose/PyMongo models
  • Seeding a local MongoDB instance with realistic fixture documents
  • Understanding Extended JSON output when debugging mongoexport or driver logs
mongodbdocumentnosqldatabaseObjectId

Validate or format this JSON

One click loads this exact example into the tool — no copy-paste needed. Format it, validate it, explore the tree, or generate TypeScript types instantly.

Frequently Asked Questions

That's MongoDB Extended JSON notation, used because ObjectId isn't a native JSON type — the $oid wrapper preserves the fact that it's a BSON ObjectId (not just a string) when the document is exported to JSON, e.g. via mongoexport. In application code with a driver, you'd normally see it as an ObjectId instance, not this wrapped form.

Embed when the data is only ever accessed together with its parent and doesn't grow unbounded (like a user's address). Reference when the related data is large, shared across multiple parents, updated independently, or could grow without limit (like a user's full order history) — MongoDB documents have a 16MB size cap.

No — if you're using Mongoose, it manages __v automatically to detect concurrent array modifications. If you're using the native MongoDB driver directly (no Mongoose), you won't see this field at all since it's an ODM convention, not a database feature.

Related JSON Examples