skip to Main Content

Mongodb – Trying to populate blogs in user but not working – mongoose

user.ts import mongoose from "mongoose"; const UserSchema=new mongoose.Schema({ _id:mongoose.Types.ObjectId, name:{ type:String, require:true }, email:{ type:String, require:true }, password:{ type:String, require:true, }, liked:[{ type: mongoose.Types.ObjectId, ref:'blogs', require:true }], myBlog:[{ type: mongoose.Types.ObjectId, ref:'blogs', require:true }] }) module.exports=mongoose.models.users||mongoose.model('users',UserSchema) blogs.ts import mongoose from "mongoose";…

VIEW QUESTION

why doesnt fastapi return my mongodb objects?

So I am trying to make a request on the route: http://127.0.0.1:8000/testadmins with the folowing function: @app.get("/testadmins/") async def get_admins(): return await get_database() get_database() is this: async def get_database(): uri = "(my mongo uri)" client = MongoClient(uri, server_api=ServerApi('1')) adms =…

VIEW QUESTION

atlas .find returning empty array while local mongodb works fine

no errors console logs [] const mongoose = require('mongoose'); const uri = "mongodb+srv://:@cluster0.yhy4bwu.mongodb.net/?retryWrites=true&w=majority"; const playerSchema = new mongoose.Schema({ fullname: String, goals: Number, assists: Number, gamesPlayed: String, shots: Number, positionCode: String, plusminus: String, team: String, timeOnIcePerGame: Number, espnId: Number }) mongoose.connect(uri)…

VIEW QUESTION

How to mock a MongoDB query .exec() in Jest?

I would like to mock this async function with Jest in a Typescript Express env. // src/helpers/user.ts import { UserModel } from "../models"; export const getUserByUsername = async (username: string) => { return UserModel.findOne({ username }).exec() } // src/models/index.ts import…

VIEW QUESTION
Back To Top
Search