Questions tagged [embedded-documents]
95 questions
14
votes
3 answers
MongoDB: How to find a document by an id inside a nested document
Given a collection like this:..
[
{
"_id" : ObjectId("5546329a470000850084a621"),
"name": "Joe",
"surname": "Smith",
"accounts": [
{
"_id" : ObjectId("5546329a470000850084a655"),
"default": true,
…

j3d
- 9,492
- 22
- 88
- 172
10
votes
1 answer
MongoDB - $addToSet on a list of Embedded Document
I have a list of (mongodb) Embedded Documents within one Document and I am interested in adding a new embedded document to the list of the existing ones.
As far as I have researched, I can use $addToSet, what I can't figure out is how does MongoDB…

Clara
- 2,935
- 6
- 34
- 49
8
votes
1 answer
Group By in mongoengine EmbeddedDocumentListField
Hi so I have this test data in mongo for mongoengine that I use for storing user's cart:
{
"_id" : ObjectId("55e492ac516ddc17a8b07d2a"),
"user" : ObjectId("55e3f236516ddc78296968be"),
"items" : [
{
"item" :…

Nazariy
- 717
- 6
- 23
8
votes
2 answers
Insert an embedded document to a new field in mongodb document
I have a document in mongodb collection like this:
{
_id: 133,
Name: "abc",
Price: 20
}
I would like to add a new field "PackSizes" which may be or not may be of an array type, and then would like to an embedded document in it.…

s.k.paul
- 7,099
- 28
- 93
- 168
5
votes
1 answer
How to add a unique index on an embedded array in Mongo DB collection
I am trying to create unique index on scorecardList.filename field in below mentioned mongo collection. The purpose is we should not be able to create another element in scorecardList with same filename.
Mongo Schema:
{
"Name": "Ravikant…

Ravikant Khond
- 51
- 5
4
votes
1 answer
MongoEngine: Getting parent document from embedded document
I am currently trying to write a generic deletion method for embedded documents in MongoEngine. I thought it would be possible to access the document object that contains an embedded document and define the delete function based on the parent…

evermean
- 1,255
- 21
- 49
4
votes
1 answer
Update an embedded document with $set
I have a document in this form
{
"firstName": "John",
"lastName": "Doe",
"preferences": {
"xxx": true,
"yyy": false,
"zzz": true
}
}
I want to update specific fields in the preferences embedded document. If I use the…

tano
- 836
- 1
- 10
- 25
4
votes
1 answer
Embedded document in change set Doctrine event listener
I am using doctrine's event listener class to implement logging of the DB events. I am using postUpdate event. I have an embedded document within my mongoDB document. Within the postUpdate event, when I call the $uow->getDocumentChangeSet($entity)…

Obaid Maroof
- 1,523
- 2
- 19
- 40
3
votes
2 answers
MongoDB - Query nested objects in nested array
I'm kindly requesting your help for this query that I need to do and I'm not very proficient yet in MongoDB. My data structure looks like this:
db.getCollection('EventDateValidation').find({}):
/* 1 */
{
"_id" :…

Gabriel
- 65
- 2
- 9
3
votes
0 answers
Mongo query multiple levels of nested document
I have a mongodb collection that has 'nested' documents. For example, a document can have the following structure:
{
"condition": {
"parameter": {
"type": "person"
}
}
}
as well as the next one:
{
…

Luis Costa
- 330
- 1
- 14
3
votes
2 answers
Mongoengine: dynamic Fields with EmbededDocuments as values
I have been using MapField till now as:
class Game(EmbeddedDocument):
iscomplete = BooleanField()
score = IntField()
#other not dynamic fields
class Progress(Document):
user = ReferenceField(User, dbref=True)
games =…

Shipra
- 1,259
- 2
- 14
- 26
3
votes
2 answers
how to validate mongodb embedded document
MongoDB 3.2 has this nice validation feature. However, in this doc it only shows me how to do the validation on first level fields. If I have the following embedded document to insert, how could I set the validation rule?
{"name": {
…

yyforyongyu
- 95
- 1
- 6
3
votes
2 answers
Add uppercase: true to mongoose embedded document
If I have two schemas, one which will be embedded in the other:
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
// Will embed this in the personSchema below
var addressSchema = new Schema({
street: String,
city: String,
…

bobbyz
- 4,946
- 3
- 31
- 42
3
votes
1 answer
Rails 4 MongoID embedded Documents
I have the following model
class Professional
include Mongoid::Document
field :first_name, type: String
field :last_name, type: String
field :company_name, type: String
field :address, type: String
validates :first_name, length: {…

Harsha M V
- 54,075
- 125
- 354
- 529
3
votes
1 answer
Parent Object In Mongoid Embedded Relation Extensions
Given a simple embedded relationship with an extension like this:
class D
include Mongoid::Document
embeds_many :es do
def m
#...
end
end
end
class E
include Mongoid::Document
embedded_in :d
end
You can say things like…

mu is too short
- 426,620
- 70
- 833
- 800