Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8437871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:33:12+00:00 2026-06-10T07:33:12+00:00

MongoDB, and mongoose.js specifically, allows tuples as attributes. For instance, the MongoDB documentation has

  • 0

MongoDB, and mongoose.js specifically, allows tuples as attributes. For instance, the MongoDB documentation has this example where the attribute comments is itself an array of objects with the attributes [{body: String, date: Date}]. Yay!

var blogSchema = new Schema({
  title:  String,
  author: String,
  body:   String,
  comments: [{ body: String, date: Date }],
  date: { type: Date, default: Date.now },
  hidden: Boolean,
  meta: {
    votes: Number,
    favs:  Number
  }
})

Now when i persist that to MongoDB, not only does each instance of blogSchema get its own value for _id (e.g. 502efea0db22660000000002) but each individual value of comment gets its own _id field.

For the most part I don’t care, but in my app the analog to comments may have thousands of values. Each of which gets its own huge value of _id.

Can I prevent that? I’ll never need to refer to them individually. Or should I learn to stop worrying and love the unique identifier? I grew up programming the Vic20 and TRS80 as a kid, so may be overly paranoid about wasting memory/storage.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:33:13+00:00Added an answer on June 10, 2026 at 7:33 am

    The _id can be disabled by setting the noId schema option to true. To pass the option you need to pass an instance of schema instead of using the object literal:

    // instead of this...
    comments: [{ body: String, date: Date }]
    
    // do this...
    var commentSchema = new Schema({ body: String, date: Date }, { noId: true });
    var blogSchema = new Schema({
      ..
      comments: [commentSchema]
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anybody has a quick example to insert an image in mongodb using mongoose and
in MongoDb I can pass a predicate to an queryable instance for example DataBase.GetCollection<BsonDocument>(entity)
Following MongoDB documentation example seems to be wrong. Any suggestion? a== 1 and a
I have nodejs application with mongodb(mongoose). like this: var mongoose = require('mongoose'); var express
I'm new to mongoose/mongodb Say I'm saving something: var instance = new TestingModel(); instance.test
I am using mongoose/nodejs to get data as json from mongodb. For using mongoose
I'm using Mongoose, MongoDB, and Node.js. I would like to define a schema where
In MongoDB I have a query which looks like this to find out for
Using MongoDB, I'm having trouble adding en element to an Array when the array
In MongoDB, what's the most efficient approach to sort an array in a document

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.