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
2
votes
1 answer

Mongoose subdocument - ID not found

I've spent a few hours with copious console.logs trying to work out why this isn't working and am missing something fundamental here: The scenario is from Simon Holmes' book on Getting MEAN (chapter 6). Apologies for copying the entire function,…
Jon M
  • 530
  • 5
  • 17
2
votes
1 answer

How to insert data into subdocument using $push in query, instead of retrieving doc and saving it back

Edit: this was actually working As the Mongoose - Subdocs: "Adding subdocs" documentation says, we can add a subdoc using the push method (i.e. parent.children.push({ name: 'Liesl' });) But I want to go further, and would like to use the $push…
charliebrownie
  • 5,777
  • 10
  • 35
  • 55
2
votes
0 answers

MEAN.js - How do you insert sub-documents into a mongoose model before saving?

Danger! I'm new to the MEAN stack. I may be using the wrong terms. I have also removed and refactored a lot of code from my example to make my question clearer. I have a schema with multiple properties, one of which is of mixed type. That mixed type…
clearwater
  • 655
  • 2
  • 7
  • 14
2
votes
1 answer

MongoDB filter multi sub-documents

I Have a document structured like this in mongo DB, and I want to filter to show only active subdocuments: active cars and active fruits. { "name":"Andre", "fruits":[ { "active":true, …
2
votes
3 answers

dynamic size of subdocument mongodb

I'm using mongodb and mongoose for my web application. The web app is used for registration for swimming competitions and each competition can have X number of races. My data structure as of now: { "_id": "1", "name": "Utmanaren", "location":…
bark
  • 33
  • 5
2
votes
1 answer

How to upsert a subdocument atomically?

I have a document structure for storing application related data for each user device. The company has some number of applications available, which is limited and not get changed so often. So I designed the document using embedded subdocument array…
iwat
  • 3,591
  • 2
  • 20
  • 24
2
votes
1 answer

Mongoose Object-literal Subdoc Not Accessible

Using Mongoose, how do I access a subdocument in an array? In the schema I have declared my subdocument using an object-literal as per the docs. After I have retrieved the parent document I can log out doc.children and see the array of objects, but…
Josh Cole
  • 1,522
  • 2
  • 12
  • 19
2
votes
2 answers

Meteor + Mongodb: is there a way to fully exclude some subdocuments from db.find()'s result?

One can easily manage existance of some fields in db.find()'s result set by specifying fields parameter (I use Meteor and test all queries on server side, in publishing function). Say Meteor.collection.find({}, { fields: { 'a': false } }) tells…
yeputons
  • 8,478
  • 34
  • 67
1
vote
0 answers

Reference sub document and then populate that subdocument on .find()

am new here. what i am trying to do is to reference a sub-document and then populate on the .find() function. My branch schema const branchSchema = mongoose.Schema( { office: [ { ...multiple office detail }, ], }, {…
1
vote
1 answer

How to paginate subdocuments in a MongoDB collection?

I have a MongoDB collection with the following data structure; [ { "_id": "1", "name": "businessName1", "reviews": [ { "_id": "1", "comment": "comment1", }, { "_id": "2", "comment":…
1
vote
1 answer

hot to get subdocument values as normal document field's value in mongodb

{ "eID" : 101, "eName" : "Radhey", "phone" : 85482245, "add" : "ffw djf ffvf", "city" : "U.P", "Salary Details" : [ { "Salary" : 56458 } …
1
vote
0 answers

Updating Mongoose Subdocument Array By ID

I am using GraphQL and Mongoose, and there is a subdocument within the document "Events" that will have an array of "tasks". I want users to be able to perform standard CRUD operations on these tasks and events, and I have been able to implement…
1
vote
1 answer

How to aggregate documents flow into a single document with an array field? (mongodb)

I have this dataSet: [ { userId: 1, nickname: 'a' }, { userId: 2, nickname: 'b' }, { userId: 3, nickname: 'c' }, ... ] And I would like, using aggregate, to achieve this form: { newField: 123456, users:…
1
vote
0 answers

How to sort results of graphLookup in subdocument

I have the following stage in my aggregation pipeline: { $graphLookup: { from: 'rateplans', startWith: '$ratePlans.parentRatePlanId', connectFromField: 'parentRatePlanId', connectToField: '_id', as:…
Mike
  • 23,542
  • 14
  • 76
  • 87
1
vote
1 answer

How to query a field inside array sub-document using ottomanjs using query builder

I could't able to query using arrays sub-document field using ottomanJS and I cant find any documentation for query building for array sub-document, any help would be appreciated. import { Schema, Query, getDefaultInstance } from "ottoman"; const …