question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can I create a DocumentArray without the sub-document _id?

See original GitHub issue

When I have such a Schema:

var StudentSchema = new Schema({
  _id : Schema.Types.ObjectId,
  clazz : { type: String, ref: 'Class' },
  number : { type: Number },
  name : [{
    lang: String,
    full : { type: String, trim: true }
  }]
});

Each name would be automatically added an _id. I would not use if for any operation my use case, how can I specify in the Schema to drop it?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
aheckmanncommented, May 28, 2013

new Schema({..}, { _id: false })

0reactions
leeseicommented, May 29, 2013

Roger that.

I started out without defining a Schema for the names and that’s why I hit the wall.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stop Mongoose from creating _id property for sub-document ...
You can create sub-documents without schema and avoid _id . Just add _id: false to your subdocument declaration. var schema = new mongoose....
Read more >
Mongoose v6.8.1: SubDocuments
Each subdocument has an _id by default. Mongoose document arrays have a special id method for searching a document array to find a...
Read more >
Stop Mongoose from creating _id property for sub ... - Intellipaat
If you want to stop Mongoose from creating _id property for sub-document array items it's very simple, you can define this in the...
Read more >
How to disable MongoDB from creating ids for subdocuments
Mongoose allows you to restrict subdocuments so that they do not have an id . Structuring your schema. First, let's create a schema...
Read more >
Stop Mongoose from creating _id property for sub-document ...
[Solved]-Stop Mongoose from creating _id property for sub-document array items-mongodb ... You can create sub-documents without schema and avoid _id .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found