All Questions
Tagged with mongodb-query mongoose-schema
255
questions
-1
votes
1
answer
19
views
I've been trying to apply unique index in combination in mongoDb databse using in my node.js backend, but unable to get away with the duplicate error
The movie is supposed to be added to the single document named as watchlist of all user, but i tried to apply unique index in combination of profile_id(user) and content_id(movie_id) so that same ...
1
vote
1
answer
38
views
How to have mongoDB populate subfields of transactions collection, for the sender and receiver, based on their _ids provided from the users collection
Here's my Mongoose Schema for the three collections users, accounts and transactions respectively:
const userSchema = new mongoose.Schema({
username: {
type: String,
required: true,...
0
votes
2
answers
27
views
Querying for deeply nested subdocuments in Mongoose
I've been having trouble trying to query for a deeply nested subdocument while using Mongoose.
My DB structure is like this:
{
"_id": "662aa6ccae109745e30dc664",
"...
0
votes
0
answers
32
views
I encountered a problem when i write a simple asynchornous function to update a data in MonogDB
i was trying to implement a javascript asynchornous code which can be able to update a data with the specified ID in MongoDB like this but as a result i got nothing as an output i dont know why?
async ...
0
votes
1
answer
46
views
How to update a field using its previous value in MongoDB with updateOne
I was trying to update the document with updateOne but got an error in code unable to access the previous value to update the field. getting type cast error. Using Mongoose version 7.0.1
...
1
vote
1
answer
79
views
Can I filter a mongo query by virtual populates?
I have a parent reference relationship between a property model and a sale model. Within my sale model, I include a field to reference the parent property:
property: {
type: mongoose.Schema....
1
vote
1
answer
38
views
Get DBRefs in one request. The Extended Reference Pattern
I have identical products that are sold in different cities at different prices.
Product.js
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ProductSchema = new Schema({
...
0
votes
1
answer
70
views
How can i populate a sub Schema in different model in mongoose
I want to populate a model which has an ObjectId of a document which is present as sub schema on another model
Sub Schema
var addressSchema = new Schema({
address: String,
phoneNumber: Number,
...
0
votes
1
answer
5k
views
How do I delete a document in mongoDB using mongoose in Node.js?
I want to delete a document from a collection in mongoDB. This is my schema:
const userSchema = new mongoose.Schema(
{
_id: {
type: String,
default: () => uuidv4().replace(/\-/g, &...
0
votes
0
answers
28
views
Populating or aggregating inside virtuals for mongoose
I had a old virtual which is used by almost around 100 queries,
AssignmentSchema.virtual('m1s', {
ref: 'M1',
localField: '_id',
foreignField: 'm2Id',
options: { match: { entityType: 'm2entity' ...
1
vote
2
answers
54
views
how to access object inside the array?
{
"_id" : ObjectId("64caa6599b2ec8d2da9e8e58"),
"message" : {
"text" : "hey"
},
"users" : [
{
&...
0
votes
1
answer
38
views
How to iterate over a mongoose schema inside another schema and update data
I have two mongoose.Schema Collection: Cities and Countries, the Cities contain only cities like this:
{city_name: "Berlin"},
{city_name: "Heraklion"},
Countries has also a ...
0
votes
2
answers
33
views
Not able to compare username in database with that entered by the client
So I am trying to create a basic authentication app without using any modules or auth strategies. Just by pushing user credentials to a MongoDb database and then by comparing the entered credentials ...
1
vote
1
answer
37
views
I want update object document fields into an array in MongoDB database
I am new to MongoDB trying to update an object field into an array in multiple documents in MongoDB.
Below I have mentioned my previous model and the new model also. I already updated the schema but I ...
0
votes
1
answer
30
views
How can I populate nested Schema?
I'm trying to populate a field in my SCHEMA.
This is my Schema
This is the GameSchema
const GameSchema = new Schema({
GameType: {
type: Number,
required: true
},
Schedule: {...