Skip to content

mongo db + node returns the connection string

I’m working on a program which scrapes all the telegram messages, but we found out we needed a simple way of inserting and reading data(crud). I chose functional programing because oop is too imitating and too complex for me(if anyone has suggestions please hit me up because I don’t know where to begin). because I wanted something like value.insert but after some research and asking cs teacher I found that this won’t work.

the function finding the data:

   connect.then( async () => {
    const dbo = client.db('telegram');
    const options = {
      projection: {_id : 1, name: 1, town: 1},
    }
   const result = await dbo.collection(collection).find(data)
    console.log(result)
  })
}

// how the function is called
Find('dev',{name: 'Red'})

the following code block is how the console.log(result); looks like

  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  [Symbol(kCapture)]: false,
  [Symbol(topology)]: Topology {
    _events: [Object: null prototype] {
      topologyDescriptionChanged: [Array],
      connectionPoolCreated: [Function (anonymous)],
      connectionPoolClosed: [Function (anonymous)],
      connectionCreated: [Function (anonymous)],
      connectionReady: [Function (anonymous)],
      connectionClosed: [Function (anonymous)],
      connectionCheckOutStarted: [Function (anonymous)],
      connectionCheckOutFailed: [Function (anonymous)],
      connectionCheckedOut: [Function (anonymous)],
      connectionCheckedIn: [Function (anonymous)],
      connectionPoolCleared: [Function (anonymous)],
      commandStarted: [Function (anonymous)],
      commandSucceeded: [Function (anonymous)],
      commandFailed: [Function (anonymous)],
      serverOpening: [Function (anonymous)],
      serverClosed: [Function (anonymous)],
      serverDescriptionChanged: [Function (anonymous)],
      topologyOpening: [Function (anonymous)],
      topologyClosed: [Function (anonymous)],
      error: [Function (anonymous)],
      timeout: [Function (anonymous)],
      close: [Function (anonymous)],
      serverHeartbeatStarted: [Function (anonymous)],
      serverHeartbeatSucceeded: [Function (anonymous)],
      serverHeartbeatFailed: [Function (anonymous)]
    },
    _eventsCount: 25,
    _maxListeners: undefined,
    bson: [Object: null prototype] {
      serialize: [Function: serialize],
      deserialize: [Function: deserialize]
    },
    s: {
      id: 0,
      options: [Object: null prototype],
      seedlist: [Array],
      state: 'connected',
      description: [TopologyDescription],
      serverSelectionTimeoutMS: 30000,
      heartbeatFrequencyMS: 10000,
      minHeartbeatFrequencyMS: 500,
      servers: [Map],
      sessionPool: [ServerSessionPool],
      sessions: Set(0) {},
      credentials: [MongoCredentials],
      clusterTime: [Object],
      connectionTimers: Set(0) {},
      detectShardedTopology: [Function: detectShardedTopology],
      detectSrvRecords: [Function: detectSrvRecords],
      srvPoller: [SrvPoller]
    },
    [Symbol(kCapture)]: false,
    [Symbol(waitQueue)]: Denque {
      _head: 3,
      _tail: 3,
      _capacity: undefined,
      _capacityMask: 3,
      _list: [Array]
    }
  },
  [Symbol(namespace)]: MongoDBNamespace { db: 'telegram', collection: 'dev' },
  [Symbol(documents)]: [],
  [Symbol(initialized)]: false,
  [Symbol(closed)]: false,
  [Symbol(killed)]: false,
  [Symbol(options)]: {
    readPreference: ReadPreference {
      mode: 'primary',
      tags: undefined,
      hedge: undefined,
      maxStalenessSeconds: undefined,
      minWireVersion: undefined
    },
    fieldsAsRaw: {},
    promoteValues: true,
    promoteBuffers: false,
    promoteLongs: true,
    serializeFunctions: false,
    ignoreUndefined: false,
    bsonRegExp: false,
    raw: false
  },
  [Symbol(filter)]: { name: 'Red' },
  [Symbol(builtOptions)]: {
    raw: false,
    promoteLongs: true,
    promoteValues: true,
    promoteBuffers: false,
    ignoreUndefined: false,
    bsonRegExp: false,
    serializeFunctions: false,
    fieldsAsRaw: {},
    readPreference: ReadPreference {
      mode: 'primary',
      tags: undefined,
      hedge: undefined,
      maxStalenessSeconds: undefined,
      minWireVersion: undefined
    }
  }
}

the expected behavior should be that it returns all the documents with the value name : Red

if it would help this is how the db looks:
enter image description here

[for the minimum text] I tried looking online if there is some stuff about a module which returns the connection string

Answer

turns out i forgot to use .toarray() to the result