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

mongodb get distinct items in array of subdocument array

What I have: I have a collection of patients, each patient has an array of subdocuments of treatments. each treatment has an array of diagnoses (which are simple string) What I want I want to get all the patients, without the treatments (but with an…
1
vote
2 answers

Lookup and aggregate multiple levels of subdocument in Mongodb

I've tried many answers to similar problems using $lookup, $unwind, and $match, but I can't get this to work for my sub-sub-subdocument situation. I have this collection, Things: { "_id" : ObjectId("5a7241f7912cfc256468cb27"), "name" :…
RealHandy
  • 534
  • 3
  • 8
  • 27
1
vote
0 answers

Generic Sub-Document API in Couchbase

I want to update specific fields in below document stored in Couchbase : "name": "Douglas Reynholm", "email": "douglas@reynholmindustries.com", "addresses": { "billing": { "line1": "123 Any Street", "line2": "Anytown ", …
Mayank
  • 11
  • 2
1
vote
1 answer

How to lookup subquery documents with another collection moongoose

I need to join user collections two times as same user will post product and purchased user details as sub document. Product Schema: { product_title: String, product_desc: String, Product_purchased:[ { userid:…
j dileep
  • 505
  • 1
  • 4
  • 11
1
vote
0 answers

Find nth level nested sub-document owner in MongoDB

I am having trouble trying to find the owner of a sub-document nested at the nth level. Here's the proposed document structure. { "_id": "foo_l0", "subdocs" : [ { "_id" : "foo_0_l1" }, { "_id" : "foo_1_l1", …
Turismo98
  • 149
  • 1
  • 1
  • 13
1
vote
1 answer

Mongoose validation fails when more than one subdocument is sent

I'm setting up a new server and I've created a mongoose Model named Announcement, that has an array of sub-documents named Image. Whenever I send more than 1 subdocument to the creation, it fails the validation that checks if the image's url mathes…
1
vote
1 answer

Mongoose - Nested SubDocuments linked to same type

I have the structure as following: --> means is included in (as property): Item --> ItemStack <--> Inventory Item: name: string, weight: number, ... ItemStack: item: Item, amount: number, inventory: Inventory | null Inventory: items: ItemStack[],…
1
vote
1 answer

Mongoose & Express: POST data from subdocument

I'm new to Express/Mongoose and backend development. I am attempting to use a Mongoose subdocument in my Schema and POST data from a form to an MLab database. I am successfully POSTing to the database when only using the parent Schema, but when I…
Nick Kinlen
  • 1,356
  • 4
  • 30
  • 58
1
vote
1 answer

Mongodb Document : Is there any way to count sub-documents with a condition?

I have documents with subdocuments where the field "stars" in the subdocuments have either "1" or "0". I want to count them at the document level based on those values in the field "stars". This is how the current document looks like: { "name":…
Ntezi
  • 33
  • 6
1
vote
1 answer

MongoDB: upsert sub document array

I have the following 'SaleOrderCol' collection: { _id: ObjectId('1000'), products: [ { _id: ObjectId('1001'), name: 'ProdA', qty: 5}, { _id: ObjectId('1002'), name: 'ProdB', qty: 10} ] }, { _id:…
elvin
  • 55
  • 7
1
vote
1 answer

How to return only ONE matching subdocument (not array) from subdocument array in MongoDB?

In my collection: { "code": xx1 "valueList": [ { "id": "yy1", "name": "name1"}, { "id": "yy2", "name": "name2"}, { "id": "yy3", "name": "name3"} ] }, { "code": xx2 …
elvin
  • 55
  • 7
1
vote
1 answer

Mongoose: How to add additional field into subdocument array

I have a question regarding mongoDB, namely mongoose: Let's say I have 2 models: 1) Product model 2) User model const ProductSchema = new Schema({ title: String, description: String, product_type: String, image_tag: String, created_at:…
Apheliont
  • 45
  • 1
  • 4
1
vote
1 answer

to update multiple nested array using array filter not working in mongoose

I am using nodeJS with mongoldb 3.6.4. I have tried the Arrayfilter to update nested subdocument. But it is not updating the value. Here is the sample code I tried ( after incorporating the comments from Anthony Winzlet to make asyn Call) var…
Raghu Vallikkat
  • 365
  • 5
  • 16
1
vote
1 answer

Are _ids in a sub document array assured to be unique within that array

MongoDB I know that if you have an array of subdocuments, and you index some field on those subdocuments, that field is only assured to be unique within the whole collection, but not within that single array. Does the same apply to the _id property…
Thiago P
  • 275
  • 5
  • 14
1
vote
0 answers

Query embedded document in mongoDB

I'm trying to query a Group document that has Users sub documents. But I only want the subdocuments that belong to the user, but I'm also getting data of other users. Look at the query result, UserStatus field, only one of them belongs to the…
Ore T
  • 29
  • 5