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

Why is no document returned while querying a sub-doc in Mongoose?

I am running the following code: var oid = new mongoose.Types.ObjectId(req.params.id); req.query = { toId : { id: oid }, deleted : false }; X.find(req.query, function (err, docs){ if(!err){ …
Michał Szydłowski
  • 3,261
  • 5
  • 33
  • 55
0
votes
1 answer

Mondodb what is the best way to retrieve a subdocument by Id, If I know parent id and sub id

Now I'm doing it like so Client.findOne({_id: client_id}, function (err, client) { if(err){ return next() } var phone = client.phones.filter(function (phone) { return phone._id === phone_id; }).pop(); …
Alex
  • 579
  • 5
  • 24
0
votes
1 answer

MongoDb subdocument array populate (via Mongoose ORM) : Does it maintain array order when populate is called

Suppose I have 2 Schema's in Mongoose that look like this: var movieSchema = mongoose.Schema({ name: String, type: String }); var moviePlaylistSchema = mongoose.Schema({ name: String, movies: [{type: mongoose.Schema.Types.ObjectId,…
0
votes
1 answer

Mongoose Subdocuments Throwing Required Validation

This is my schema // grab the things we need var mongoose = require('mongoose'); var Schema = mongoose.Schema; var UserSchema = require('./user'); var inviteeSchema = new Schema({ email: { type: String, required: true, unique: true }, phone: {…
Krishnandu Sarkar
  • 494
  • 1
  • 6
  • 21
0
votes
1 answer

match subdocument within another subdocument same document

I have the following documents in my collection : { "_id": ObjectId('555a33d69487b45401ec1149'), "nombre": "demo", "roles": [ { "id": ObjectId('556ca1999487009c1fac125f'), "nombre": "rol1" }, { "id":…
Luis Felipe Garcia
  • 148
  • 1
  • 3
  • 11
0
votes
0 answers

Optimizing Spring MongoDB Query Against Subdocuments in List

I'm getting poor query performance from a Spring/Mongo application where I have a document that contains a list of subdocuments. I've tried adding compound indexes to help with specific queries, but they don't seem to help much when I'm searching…
Neil Davis
  • 31
  • 4
0
votes
1 answer

MongoDB find() to return the sub document when a (field,value) is matched

This is a single collection which has 2 json files. I am searching for a particular field: value in an object and the entire sub document must be returned in case of a match ( That particular sub document from the collection must be returned out of…
Vamshi
  • 97
  • 10
0
votes
0 answers

Updating 3rd tier document in subarray

I have a document as follows (in a Projects collection): title: "title" company: "company" companyID: "companyID" category: "category" starred: false createdAt: new Date tasks: [ { …
offthegrass
  • 446
  • 1
  • 6
  • 16
0
votes
1 answer

How to find a sub document in mongoose without using _id fields but using multiple properties

I have a sample schema like this - Comment.add({ text:String, url:{type:String,unique:true}, username:String, timestamp:{type:Date,default:Date} }); Feed.add({ url:{type:String, unique:true }, username:String, …
Harshit Laddha
  • 2,044
  • 8
  • 34
  • 64
0
votes
1 answer

how to update sub document having key and value in mongodb using php

Hi i am new to mongodb and i am using PHP here. I want to update the sub-document with an array like below to existing document. [weeksAtOne] => Array ( [156] => 1586 ) when i try to call the below functions $query = array('decade'…
0
votes
1 answer

Subtract subdocuments from collection in aggregate pipeline

I'm trying to retrieve a document from a mongodb and remove some objects from an array based on a condition (deleted != null). Here is a simplified example of the item I'm targeting: { "_id" : ObjectId("54ec9cac83a214491d2110f4"), "name" :…
Simon
  • 35
  • 1
  • 5
0
votes
1 answer

Removing an element from an array of subdocuments by subdocumentId

So I have the following schema: var questionsSchema = new Schema({ nr: Number, points: Number, description: String, groups: [{ type: Schema.Types.ObjectId, ref: 'Group', default:…
Robin-Hoodie
  • 4,886
  • 4
  • 30
  • 63
0
votes
0 answers

MongoDB GeoSpatial Query on subdocument C#

I've successfully got var locations = MongoCollection.Find(Query.Within("Position", poly)) to return the correct results when my document has this structure: class Location { [BsonId] public int Id { get;…
Stringer Bell
  • 265
  • 1
  • 4
  • 13
0
votes
1 answer

Fetching subdocuments with angular $http

Say you have nested collections a, b, and c, which follow the following map: {"collection":"a", "children":[{"collection":"b", "name":"bee", "children"[{"collection":"c","name":"cee"}]}]} And here is a1, fetched from a…
Manube
  • 5,110
  • 3
  • 35
  • 59
0
votes
1 answer

MongoDb Aggregate per subdocument

I have these collections, stats and items. Stats has one item as subdocument: var ItemSchema = new Schema({ type: String, created_at: Date, updated_at: { type: Date, default: Date.now() } }); var StatsSchema = new…
michelem
  • 14,430
  • 5
  • 50
  • 66