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

Find a specific subdocument Mongoose

I currently find the main document, in this case User, then loop over user.characters and find the correct subdocument and return it. getSingleCharacter: async function (req, res) { // uses req.params.characterName to search for a character …
2
votes
1 answer

I'm trying to save an array from subdocuments inside other subdocument but it does not

Im trying to save this, but mongoose does not. This is the api, model and what the console show me. newExam = async (req, res)=>{ hasItUsernameTwo(req,res) const user = await User.findById(req.user), examData =…
2
votes
1 answer

Mongodb Update subdocument values matching subdocument and without altering other fields

I have a schema like this { "_id": "5f86da4b5bb9a62742371409", "status" : true, "doc": [ { "_id": "5f86cacbe4d7c423f21faf50", "a": 4, "b": null }, { "_id": "5f86cb01a1ca5124063299c1", …
niksmac
  • 2,667
  • 3
  • 34
  • 50
2
votes
1 answer

Sub-Document Mutate operations not working properly with XDCR

We have setup 2 couchbase clusters with XDCR between them. We are using sub-doc mutate to update document with new fields (there is no removal of any field, also no field is being overridden/updated). We found out that if we are updating same…
2
votes
0 answers

how to add data to subdocument using form in mongoose using nodejs dynamically

I have schema like this and subdocument array in the schema const mongoose = require('mongoose'); const pengirimanTabungChild = new mongoose.Schema({ tujuan : { type : String, required : true }, jumlahTabung : { …
Bryan Lumbantobing
  • 604
  • 1
  • 7
  • 22
2
votes
0 answers

Best practice for retrieving a Couchbase sub document from a replica bucket?

I am using Couchbase to build an in-memory cache of DocumentFragment[Lookup]s. This is made easy by using the sub-document api. val fragment: DocumentFragment[Lookup] = bucket.lookupIn("key").get("some.path", "some.other.path").execute() Couchbase…
kunrush
  • 61
  • 5
2
votes
1 answer

Increment nested field value in mongodb if exists or create nested fields

I need to increment the multi level nested field value if it exists or create the complete nested field Object structure. Structure of my document Doc1 { _id:ObjectId(), myField: { nested:{ x: 5, y: 10, z: 20 } } } Goal…
nikhil024
  • 435
  • 5
  • 19
2
votes
1 answer

Having trouble finding/or implementing the correct mongoDb method to find and update subdocument

I'm trying to update a specific field in a subdocument based on its Id and the Id of the parent document. I'm new to this so I may be misunderstanding the mongoDb documentation but as far as I can tell findOneAndUpdate should be working. I've also…
2
votes
2 answers

Mongoose - Delete property from SubDocument

I have the following Mongoose schema and code: Schema: { ... inv: { type: Object, default: {} }, ... } Code (version 1), where targetData is a Mongoose Document, item is a String, and amount is a…
APixel Visuals
  • 1,508
  • 4
  • 20
  • 38
2
votes
1 answer

MongoDB index on subdocuments keys

Is it possible to create a mongodb index on subdocuments keys which can be different in each document? For instance if we have { _id: 1, languages: { en: {...}, fr: {...}, de: {...} } }, { _id: 2, …
mtonev
  • 327
  • 3
  • 7
2
votes
1 answer

Find document by ID and push another subdocument

I have two Collection schemas, and I want to insert one Model instance of one schema (FA) inside an array field of the other Model schema (FP): var FASchema = new Schema({ Timestamp: Date, PrognostizierterBetriebswert: Number, …
MMMM
  • 3,320
  • 8
  • 43
  • 80
2
votes
1 answer

getting the value of the newly created/pushed element of a subdocument mongoose

I'm creating a mern app and new to mongodb/mongoose. And I'm currently using nested document model in my schema. I was able to create elements in the nested document/subdocument by using push but I'm not able to return the newly pushed element as a…
Ndx
  • 517
  • 2
  • 12
  • 29
2
votes
0 answers

Update field of subdocument in array

I've searched across the site of course, but it seems that there is confusing terminology regarding what is a "subdocument"... Imagine we have two collections (Pages and Items) with the following schemas: Item: _id: ObjectId name: String Page: …
Artico
  • 101
  • 6
2
votes
1 answer

Is it possible to return multiple subdocuments with mongoDB and Node.js?

I currently have a schema which currently looks like: var User = new Schema({ id: String, firstName: String, lastName: String, password: String, username: String, position: [{ title: String, location:…
user
  • 395
  • 2
  • 11
  • 28
2
votes
1 answer

MongoDB indexes on subdocuments not being used based on syntax of query

I'm using Meteor with MongoDB with a collection of documents like this: {a: 'a1', b: 'b1', c: { d: 'd1', e: 'e1' } } I initially created an index like this: collection._ensureIndex({'c.d': 1}); And ran queries like…
Hashcut
  • 833
  • 1
  • 5
  • 19
1 2
3
19 20