Questions tagged [subdocument]

Concept in document-oriented databases, where a field in document is a document in itself.

Concept in document-oriented databases, where a field in document is a document in itself.

Example document as JSON, where address is a subdocument:

{
    name: "Snake",
    address: {
       street: "742 Evergreen Terrace",
       city: "Springfield"
    }
}
288 questions
0
votes
0 answers

getting the sub-document with the document in mongoose.findOne

First, my code is working well, but i don t know if doing the right thing. I have a parent model Units with this schema { info: {...}, chapters: {_id: string, ...} } the chapter schema is like this: { info: {...}, content: string } now in…
med morad
  • 497
  • 4
  • 12
0
votes
1 answer

Why "duplicate key error" when inserting subdocument arrays?

I have a Mongoose Schema in which I use subdocuments. Their definitions are: const vraagSchema = new mongoose.Schema({ vraagNummer: { type: Number, required: true, min: 1 }, vraagTekst: { type: String, minLength: 1, …
bjorn_h
  • 139
  • 3
  • 12
0
votes
1 answer

Cant get specific subdoc and a 'root' value in the same call

I can get the specific sub document, but I want to have the email also //The object in the Db looks like this: { _id: some_id, email: "an email", order: [{ fakturaId: faktura_id, name: "Some name" ... …
user3540877
  • 55
  • 1
  • 5
0
votes
0 answers

In Mongoose how do I find a document based on a date range in a subdocument

I have a node.js api, using mongoose, and mongo and an already existing database. I need to add the ability to query based on a subdocument date range. I can get the aggregation query to work in MongoDB using Robo3T but I cannot get the same query…
0
votes
0 answers

Updating Field in a Nested Subdocument MongoDB

I'm trying to update the IsActive flag inside the function object, however, it is deeply nested inside the Companies and Factories Objects. Trying to use $ is no use, as it does not work with deeply nested subdocuments. Has anyone found a way to…
0
votes
1 answer

Find Documents whose Subdocument Fields partially match given Criteria with Mongoose

I have using nodeJS and mongoose/mongoDB to build an API. Consider the following model for a generic Model (Gmodel): { name: "teleni", type: "person", data: mixed } The data field in this document is a mixed type so it can be anything, but…
teleni
  • 13
  • 4
0
votes
1 answer

Query on Nested Array

How can i find only one document which matches my filter machine_name: ABT6 and process days : 33 I need only one doc to be returned. [ { "_id": "5a7ca2227c42ac67682731d5", "machine_name": "ABT6", "process": [ { …
Ally Makongo
  • 269
  • 5
  • 14
0
votes
1 answer

How to POST, PATCH and DELETE items from a subdocument array using REST

Let's say we had the following User document: { "_id": "1", "firstName": "Joe", "hobbies": [ "_id": "1", "name": "music", "talented": true ], } So let's say we wanted to POST, PATCH or DELETE one of Joey's hobbies. How…
netishix
  • 183
  • 4
  • 10
0
votes
1 answer

How to iterate on mongoose subdocument array of objects

Trying to implement conditional statement relying on subdocument array of objects, so i need to iterate over collection of users in database and check inside each user subdocument array of objects with findIndex as for javascript Users…
Ahmed Younes
  • 964
  • 12
  • 17
0
votes
1 answer

How to get a specific subdocument

I have this particular schema var CategorySchema=mongoose.Schema({ name:{ type:String, index:true, unique:true }, commission:{ type:Number }, subCategories:[{ name:{ …
hassanqshi
  • 353
  • 2
  • 9
0
votes
2 answers

How to remove subdocument (by Id) embedded in sub array in MongoDB?

ProductCollection: { _id: { ObjectId('x1')}, products: [ { listPrice: '1.90', product: {id: 'xxx1'} }, { listPrice: '3.90', product: {id: 'xxx2'} }, { listPrice: '5.90', product: {id: 'xxx3'} } …
elvin
  • 55
  • 7
0
votes
2 answers

How to get all Ids from array embedded within array using Lodash?

I have this 'Products' array (contain 'Product' sub documents, each with its own unique Id): Products: [ { listPrice: '1.90', Product: {id: 'xxx1'} }, { listPrice: '3.90', Product: {id: 'xxx2'} }, { listPrice:…
elvin
  • 55
  • 7
0
votes
1 answer

Removing subdocument in mongoose

I have a model like this: const Screen = new Schema( { userId: [ { type: ObjectId, default: null } ], contents: [ { content: { …
0
votes
1 answer

mongoose subdocument field.id giving undefined

in this code i need to take batch_results using its genarated id like described in mongoose documents const mongoose = require('mongoose'); const Schema = mongoose.Schema; const config = require('../config/config'); // Result schema const…
ALPHA
  • 1,135
  • 1
  • 8
  • 18
0
votes
1 answer

Mongoose: Pushing an object to an array of objects

I've looking over various other similar questions and just can't seem to make sense of why I can't push an object of just 2 numbers to an array. The examples I've tried copying from are these: Mongoose findOneAndUpdate: update an object in an array…
AustinFoss
  • 385
  • 5
  • 13