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
1
vote
0 answers

meanjs controller for subdocument

I have architectural question about how to design my meanjs controller and routes for mongoose subdocuments. my model looks as following: 'use strict'; /** * Module dependencies. */ var mongoose = require('mongoose'), Schema =…
mstampfli
  • 21
  • 3
1
vote
1 answer

Is there a way to push a sub document into mongodb array only if the condition is satisfied?

i am pushing sub documents into an array. Basically the subdocs are something like this: { id:"someId", date:Date } i want to add new subdoc only if the theres no other subdoc with matching id.I found $addToSet modifier on mongodb documentation…
nikoss
  • 3,254
  • 2
  • 26
  • 40
1
vote
1 answer

Get only subdocument array by field

I have the following ServiceProvider collection. { "_id" : ObjectId("5724a838588aeca6158b4567"), "ServiceProviderID" : 3, "Title" : "test1", "PostedMessage" : "test1", "TotalComments" : 0, "TotalShares" : 0, "TotalThanks"…
Chinmay Waghmare
  • 5,368
  • 2
  • 43
  • 68
1
vote
1 answer

Group of subdocuments not fetching the correct value

I am using AngularJS to group all subdocuments of array. it is able to group only the first item of the subdocument and gives the length how do i get the count of its proper length. My plunk link. the result i am getting now is Isnain Meals -…
Rohit Vinay
  • 665
  • 7
  • 38
1
vote
2 answers

MongoDB: how to insert a sub-document?

I am using sub-documents in my MEAN project, to handle orders and items per order. These are my (simplified) schemas: var itemPerOrderSchema = new mongoose.Schema({ itemId: String, count: Number }); var OrderSchema = new mongoose.Schema({ …
MarcoS
  • 17,323
  • 24
  • 96
  • 174
1
vote
1 answer

Mongodb : Pull out subdocument from a document

My database schema looks like this: { "_id" : 137, "name" : "Tamika Schildgen", "scores" : [ { "score" : 4.433956226109692, "type" : "exam" }, { "type" : "quiz", "score" : 65.50313785402548 }, { …
clever_bassi
  • 2,392
  • 2
  • 24
  • 43
1
vote
0 answers

Mongoose $push - no errors when: inserting object with existing unique field + inserting trash

What I'm trying to accomplish is to have an Array of Objects (the subdocument way: defined in a Schema) inside a main document, and I want this subdocument to behave as a document itself. This is, when pushing an Object into the Subdocument Array, I…
charliebrownie
  • 5,777
  • 10
  • 35
  • 55
1
vote
0 answers

findOneAndUpdate subdocument fields are overwriten

I have a shema with nested documents: var BlogSchema = new mongoose.Schema({ ... comments : [Comments], ... }); and trying to update a comment router.post('/comments/:id', function (req, res, next) { …
anton
  • 247
  • 3
  • 13
1
vote
1 answer

How to Search MongoDB Nested Subdocuments Within Different Deeps

I'm having some subdocument in MongoDB that occasionally include different types - string, another subdocument, another nested subdocument etc. I'm trying to build a query that will search within this subdocument content regardless of it's…
Do5
  • 13
  • 3
1
vote
1 answer

Mongoose sub document pre remove middleware not called

I would prevent any sub document from being removed, thus I added an error to the pre('remove') middleware of each sub document Schema. When calling the .remove() function, it effectively calls the middleware. But when it is deleted without calling…
Musinux
  • 31
  • 6
1
vote
1 answer

How can I return the minimum values from two subdocuments in a collection using MongoDB's aggregation pipeline?

We have a bunch of products in a database with two types of monetary values attached to each. Each object has a manufacturer, a range and a description, and each object can have a monthly rental amount (for rental agreements), a monthly payment…
abitgone
  • 561
  • 9
  • 29
1
vote
0 answers

Using .elemMatch to match an attribute to one of the parent documents fields.

I have been struggling for a while now and i can't seem to find an answer here. I want to filter an array of subschemas in a subdocument by removing the ones that exist in an already specified list (using $nin:). My problem is that the list I want…
arneson
  • 141
  • 8
1
vote
1 answer

How can I update the sub document field from the sub document array based on the query?

{ "_id": ObjectId("552cd780e4b042752e540df5"), "source": [ { "bookid": ObjectId("552cd77e31456e192df6ad8e"), "isActive": false }, { "bookid": ObjectId("552cd77e31456e192df6ad8a"), "isActive": true …
1
vote
2 answers

Using pull in mongoose model

Should this work? I am trying to remove a single subdocument (following) from a document (this) in the UserSchema model. UserSchema.methods.unFollow = function( id ) { var user = this return Q.Promise( function ( resolve, reject, notify ) { var…
Noah
  • 4,601
  • 9
  • 39
  • 52
1
vote
1 answer

mongo db add subdocuments from another collection

I have two collections awards teams have won and a list of teams. I want to ETL the whole of awards into the other (teams) as subdocuments with some minor transformations, but I only get one subdocument from the awards into teams. Here is the code…