Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
GraphQL Mongoose con MongoDB Atlas devuelve una matriz vacía

Estoy tratando de conectar MongoDB Atlas y mangosta, pero el servidor siempre devuelve una matriz vacía '[]'. Cuando cargo datos simulados, todo funciona (los datos simulados y MongoDB Atlas tienen los mismos valores). Me conecté a MongoDB Atlas, pero no puedo obtener algunos datos.

Controlador:

 const express = require('express') const { ApolloServer } = require('apollo-server-express') const { createServer } = require('http') const mongoose = require('mongoose') const typeDefs = require('./schema') const resolvers = require('./resolvers') const app = express() const server = new ApolloServer({ typeDefs, resolvers, playground: { endpoint: 'http://localhost:3000/graphql', settings: { 'editor.theme': 'light' } } }) server.applyMiddleware({ app }) const httpServer = createServer(app) server.installSubscriptionHandlers(httpServer) mongoose .connect(`mongodb+srv://<username>:<password>@cluster0.brdqp.mongodb.net/${process.env.mongoDatabase}?retryWrites=true&w=majority`, { useNewUrlParser: true, useUnifiedTopology: true }) .then((res) => { httpServer.listen(3000, () => { console.log('connected!') }) }) .catch((err) => { console.error('Error while connecting to MongoDB', err); })

Esquema:

 const { gql } = require('apollo-server-express') const typeDefs = gql` type Todo { _id: String, title: String, description: String status: String date: String } type Query { todos: [Todo] } ` module.exports = typeDefs

Resolutores:

 const { Todo, Restaurant, Customer, Order } = require('./models') const pubsub = require('./pubsub') const resolvers = { Query: { todos(parent, args, context, info) { return Todo.find() .then(todo => { return todo.map(r => ({ ...r._doc })) }) .catch(err => { console.error(err) }) }, }, } module.exports = resolvers

Colección MongoDB Atlas : (Nombre de la base de datos: nodo, nombre de la colección en la base de datos: todo)

 _id : 5c9bdb721c9d440000345d62 title : "question" desctiption : "test test" status: done date: 1

Pero el servidor siempre devuelve [ ] ¿Cómo???? Por qué&?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!