Skip to content

chapter 1: setting up mongodb #3

@cdrani

Description

@cdrani

If you are using mongodb version >= 3, then you need to tweak this section a little bit:
/index.js

MongoClient.connect(MONGO_URL, (err, client) => {
  assert.equal(null, err)
  console.log('Connection Approved')
  const collection = client.db('test').collection('users')

  const rli = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  })

  rli.question('Client Request: ', inputQuery => {
    graphql(schema, inputQuery, {}, { collection })
      .then(result => {
        console.log('Server Response: ', result.data)
        client.close(() => rli.close())
      })
  })
})

/schema/main.js

usersCount: {
  type: GraphQLInt,
  resolve: (_, args, { collection }) => collection.count()
}

Reference this: https://stackoverflow.com/a/47694265/8876839

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions