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

Pushing to array which is in an array of objects

{ "_id": { "$oid": "5bd8fa85bfbf4e27d86c73eb" }, "status": { "iat": 1540947201356, "exp": 1540950801358 }, "code": "1cmTwKC7", "mongoDate": { "$date": "2018-10-31T00:41:56.016Z" }, …
Kai Ferrall
  • 81
  • 2
  • 12
0
votes
1 answer

MongoDB - Update subdocuments using javascript

The documents in my apps collection each contain a subcollection of users. Now I need to update a single user per app given a set of _ids for the apps collection using javascript. I cannot use a regular call to update() for this, as the data…
l'arbre
  • 719
  • 2
  • 10
  • 29
0
votes
3 answers

Node.js/mongoose - sub-document in a array won't delete/remove

So this is my first on-my-own node.js project after finishing up an online Bootcamp. Running into trouble removing a sub-doc in my array. Here's some code, I hope I provide enough info for someone to help me out. models: var productSchema = new…
Smiggez
  • 21
  • 1
  • 7
0
votes
1 answer

MongoDB update a specific item of sub document (array) based on condition?

I have a PostSchema which has a property array called votedBy:[],this is of type votedBySchema.Like below: var votedBySchema = new Schema({ voteType:{ type:Boolean,default:false }, voter:{ type:Schema.Types.ObjectId } }); const PostSchema =…
Aniket Jha
  • 1,751
  • 11
  • 13
0
votes
2 answers

mongodb return just the subdocument by querying the field

I have a structure like this: { "_id" : ObjectId("5b155aa3e7179a6034c6dd5b"), "pinnedKpi" : { "Ver01" : [ "130", "138", "122", "134" ], "Ver02" : [ "265", "263", "142", …
JohnSnow
  • 6,911
  • 8
  • 23
  • 44
0
votes
1 answer

Why MongoDB subdocument expiration removes parent document?

I use mongoose 5 and have a schemas like this: user.js const mongoose = require('mongoose'); const GeoData = require('./geodata'); const UserSchema = new mongoose.Schema({ name: { type: String, required: true }, createdAt: { type:…
gutaker
  • 181
  • 3
  • 10
0
votes
1 answer

mongodb only updates first matching item of subdocument eventhough it should select more

I am trying to increment all selected items of a subdocument that matches my criteria My problem is that it only updates the first matching item. I select my Project(saved as Highlights model) by id. Select all items from subdocument 'highlights',…
0
votes
1 answer

MongoDB finding within embedded documents

Using the example found at: https://docs.mongodb.com/manual/tutorial/query-array-of-documents/ Having: db.inventory.insertMany( [ { item: "journal", instock: [ { warehouse: "A", qty: 5 }, { warehouse: "C", qty: 15 } ] }, { item: "notebook",…
Nelson La Rocca
  • 173
  • 1
  • 9
0
votes
1 answer

Mongoose - why isn't subdocument working?

I'm making a polling app and I would like to save users who have voted on a poll based either on their user ID, IP address or MAC address. I figured it would be straight forward by having a voted: VotedSchema attribute in my Poll model, but for some…
doctopus
  • 5,349
  • 8
  • 53
  • 105
0
votes
1 answer

mongoose/mongodb subdocument deep query and update

Schema var chapterSchema = new Schema({_id: Number, completed: Boolean}) var bookSchema = new Schema({ date: { type: Date, default: Date.now }, author: String, chapter: chapterSchema }) var personSchema = new Schema({ _id: Number, name: String,…
Prakash Ramasamy
  • 385
  • 1
  • 7
  • 15
0
votes
1 answer

mongoose and subcollection approach

Im starting my own project - portal about football club with simple CMS in react/redux and nodejs. I want allow ppl to answer to another comment. I thought about subcollection in mongoose. I would have main collection called COMMENT. It would have…
Xaoo
  • 167
  • 1
  • 3
  • 9
0
votes
1 answer

A query to return a single attribute of a document in mongodb

[ "_id" : ObjectId("59d1f4d0539f772aacf90f61"), "user_id" : 1222.0, "user_name" : "jadenn", "email" : "jdkdkdjjjjjjjjjjjjjjjjjjjh@j.com", "phone" : 333333333.0, "image_ref" : "static/image/123IMG_20170917_232813.jpg", …
Khushhal
  • 91
  • 1
  • 8
0
votes
0 answers

How can I get the elements from a mongodb subdocument in java?

I have a mongodb database ("testing") which has some collections. I use one named "Pelis3" which contains documents. The documents contains the typical elements and a subdocument named "belongs to collection" where i will to access. The problem is…
Daniel Ruiz
  • 331
  • 1
  • 3
  • 18
0
votes
1 answer

Issues updating subdocuments in mongodb

Excuse if this is a silly question, but I'm quite new to mongo. I have documents with subdocument listed under films. I'm updating a single subdocument without issue on my localhost using; db.update( { _id: req.params.id, 'films.filmId':…
designkai
  • 15
  • 4
0
votes
1 answer

RESTHeart filtering and sorting by sub documents property

I m working with mongodb and restheart. In my nosql db i have a unique document with this structure: { "_id": "docID", "users": [ { "userID": "12", "elements": [ { …
Alex
  • 1,515
  • 2
  • 22
  • 44