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

How to delete a subdoc in mongoose + nodejs + express

How do you remove a subdoc named task? The parent schema is User and the child schema is named Task. Here is my route: app.delete('/api/tasks/:id', isAuthenticated, function (req, res) { User.update({ 'task._id': req.params.id }, { $pull: {…
weebsta
  • 82
  • 1
  • 6
0
votes
1 answer

mongodb multikey index bounds in arrays of subdocs

For background, the page from the docs that seems most relevant to my question is this page on multikey index bounds and index intersection. I'm having an issue where it seems like mongo is not properly combining index boundaries in an $elemMatch…
underrun
  • 6,713
  • 2
  • 41
  • 53
0
votes
0 answers

Mongoose: Instance methods on subdocs

Consider an album that has many songs. I define the Album schema as such that it has the Songs as subdocs. But I'm not sure how do we create instance method for subdocuments. Consider the schema as below: // Sub Document var SongSchema = new…
Ananth
  • 767
  • 1
  • 7
  • 15
0
votes
2 answers

Mongodb: Querying array of subdocuments

I have users' collection whose schema is like: { _id: unique number, name: 'asdf', age: '12', gender: 'm', address: [ {area: 'sdf', city: 'sdq', state: 'wfw'}, {area: 'asdf', city: 'sdfs', state: 'vfdwd'} …
harshad
  • 410
  • 4
  • 17
0
votes
1 answer

append to multi-dimensional subdocument

I want to add a new filed like "email" for each sub document in groups { "_id" : 10, "groups" : [ { "members" : ["Mark"], "name" : "My Friends" }, { "name" :…
user3807753
  • 59
  • 1
  • 1
  • 3
0
votes
0 answers

Finding matching documents with only matching subdocuments MongoDB

I am facing always the same thing when I would like to query macting subdocuments of an array. Lets think I have a collection like below: { "_id" : 1, "value" : 5, "array" :[ {"name" : "John", "born" : ISODate("1980-04-17T13:11:54Z"), …
C.Kaya
  • 21
  • 1
  • 4
0
votes
1 answer

Return _id of upserted subdocument

I've looked everywhere and can't figure this out. How can we return the auto-generated _id for an upserted subdocument in MongoDB/Mongoose? Here's my Schema: var commentsSchema = new mongoose.Schema({ sid : { type : mongoose.Schema.ObjectId }, //…
cybermach
  • 125
  • 1
  • 6
0
votes
1 answer

Index and upsert a mongo subdocument

I was working on mongo and I'd like to do the following things: when a set of (lat, lon, uid) comes in: 1. the collection has lat as unique index, also for each lat the lon index is unique 2. if (lat, lon) pair exists in this collection, update uid…
Shih-Min Lee
  • 9,350
  • 7
  • 37
  • 67
0
votes
1 answer

MongoDb - $match filter not working in subdocument

This is Collection Structure [{ "_id" : "....", "name" : "aaaa", "level_max_leaves" : [ { level : "ObjectIdString 1", …
Ranjith
  • 2,779
  • 3
  • 22
  • 41
0
votes
3 answers

MongoDB update a subdocument attribute

Let me start by saying I'm sorry if this has been answered, but I can't get other questions on this site to fit my needs and, more importantly, work. I have the below example document, with a subdocument of 'address': { "_id" :…
JAC2703
  • 423
  • 6
  • 22
0
votes
1 answer

mongoDB documents with subdocuments

I have the following structure: Collection document message field 1 field 2 field 3 The document will start like before, I will need to find the document by searching like: db.document.find( { "message.field1": "a" } ) and when…
David Villasmil
  • 395
  • 2
  • 19
0
votes
1 answer

mongodb unexpected behavior when saving subdocs

I do this after a mongoose .find query: data2[0].videos[temp].markModified('fakeName'); data2[0].save(function(err,product,numberAffected){ if(err){ console.log("error saving manifest") console.log(err); var…
user773737
0
votes
2 answers

Updated nested subdocuments in MongoDB

I am trying to update nested subdocument in mongodb, { id: 100, status: [ { campaigns: [ { timestamp: "2014-07-30", task: [ { …
Ayyanar G
  • 1,545
  • 1
  • 11
  • 24
0
votes
1 answer

Mongo query against subdocument with a top N

I've got the following data in a user collection in MongoDB: { "_id" : ObjectId("53807beee4b0d2b25747df7e"), "allowedAppIds" : [ { "appId" : "534c8d2ce4b024b1f08e16e6", "createdDate" :…
0
votes
0 answers

In mongodb : do subdocs get deleted when the array is overridden?

In the following snippet I am using mongoose and mongo db. The elements of arr property of TestSchema have different _id's after saving it the second time. Does that mean that the subdoc after the first save was automatically deleted after the…
Nitiraj
  • 614
  • 1
  • 4
  • 15