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

MongoSpark - convert bson Document to Map[String, Double]

In my MongoDB database I have a collection of the following documents: As one can see, each document has some nested documents (Decade, Title, Plot, Genres, etc.). Those are kinda Map representations of SparseVectors that I came up with. And are…
1
vote
1 answer

Mongoose - Validate array of different subdocuments types

I have a schema which has an array of different sub document types. Below schema is just an example: VehicleSchema: let BikeSchema = new Schema({ title : { type: String, required: [true, 'title is required'] }, type : { type:…
1
vote
1 answer

How can I make a subdocument expire at a particular date in mongoose?

I have the following Schema for a virtual classroom in mongoose: var classroomSchema = mongoose.Schema({ studentIds: [mongoose.Schema.Types.ObjectId], teacherIds: [mongoose.Schema.Types.ObjectId], teacherNames: [String], createdAt:…
lightbringer
  • 399
  • 4
  • 19
1
vote
1 answer

Query document and select subdocument

I want to select a subdocument using mgo. Before select, the query should query the right top level document. I tried this: name := "anything" w := models.Wallet{} c := s.DB("ep2").C("users") err := c.Find(bson.M{"name":…
nayD93
  • 13
  • 2
1
vote
0 answers

MongoDB/Mongoose find on the basis of embedded document in array, then update and save

This is my mongodb schema var Client = new Schema({ name: String, race: [{ name: String, car: [{name: String}] }] }); I want to find a car by _id, something like this: Client.findOne({ "race.car._id":…
visconti
  • 45
  • 1
  • 5
1
vote
0 answers

Query top level array of subdocs with MONGOOSE, to only return N most recent subdocuments in array

I'm looking for the conditions, fields, etc that i would need in a query, or an async flow to query a single document which has an array of subdocuments at the top-level. Model: let postSchema = new mongoose.Schema({ date : {type: Boolean,…
jlmurph
  • 1,050
  • 8
  • 17
1
vote
0 answers

Filter subdocument in MongoDB

We are new to Mongodb, as part of our POC, we ingested a bunch of documents into Mongo and testing out different query and projection options for data retrieval. One of the use cases, we are trying to filtering below sample document in Mongo and get…
athenatechie
  • 699
  • 2
  • 8
  • 15
1
vote
1 answer

$unwind nested document and $match

I have a nested document which looks like: var User = new Schema({ id: String, position: [{ title: String, applied:[{ candidate_id: String, name: String }], }], What I…
user
  • 395
  • 2
  • 11
  • 28
1
vote
0 answers

couchbase subdocument arrayAddUnique not working for non string objects

GOT this error The unique value provided is not a JSON primitive arrayAddUnique public AsyncMutateInBuilder arrayAddUnique(String path, T value, boolean…
yausername
  • 750
  • 5
  • 15
1
vote
2 answers

Meteor/Mongodb - arrays, subdocuments & overlapping subscriptions

I'm making a game; players form leagues and make competing predictions. A league looks like this: { leagueName: "Premier League", players:[ {name: "Goodie", secretPrediction: "abc"}, {name: "Baddie", secretPrediction: "def"} …
rubie
  • 1,906
  • 2
  • 20
  • 26
1
vote
2 answers

Trouble in inserting sub-documents using mongoose

I created an Enterprise database using mongoose in node-express project.Now I need to add employee sub document in the enterprise_employee field of the enterprise database, but it throws an error. Following code snippet is my schema var mongoose=…
akila arasan
  • 737
  • 3
  • 11
  • 26
1
vote
1 answer

Retrieve value from parent in MongoDB sub-document

I have two schemas childrenSchema = new Schema({ name: String }); parentSchema = new Schema({ type: String, children: [childrenSchema] }); Now I want a method in childrenSchema from which I retrieve the type of the parent. I guess it is…
Jamgreen
  • 10,329
  • 29
  • 113
  • 224
1
vote
1 answer

How to update MongoDB documents with arrays of sub-documents

I am working with a MongoDB database whose collections model classes, students, subjects, and [academic] performance. Below are the Mongoose based schema and models: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var ObjectId =…
Web User
  • 7,438
  • 14
  • 64
  • 92
1
vote
1 answer

How to add multiple ObjectIds using addToSet with Mongoose?

I am trying to use mongoose addToSet to add multiple ObjectIds to a sub-doc array. I've used a similar method for adding a single subdocument, but I'm trying to figure out how to add multiple subdocuments. Project Model import mongoose from…
Jasmin
  • 39
  • 7
1
vote
0 answers

Mongoose schema : SubDocument field only unique per Document

I have a little question. I have a User schema which contains a table fields redirecting to the Table schema. A Table element can contain a name, I want this name to be unique per User but not between User. Example: User1 -> Table1.name: "foo" User2…
Naguib 凪
  • 25
  • 6