Home > Enterprise >  Unable to retrieve value from database
Unable to retrieve value from database

Time:05-23

There is such a data structure
(for example, I will give 3 elements, in fact there are several million of them)

   '6444': [
    { TICKER: 'EURUSD' },
    { DTYYYYMMDD: '20030509' },
    { TIME: '142300' },
    { OPEN: '1.14888' },
    { HIGH: '1.14898' },
    { LOW: '1.14881' },
    { CLOSE: '1.14889' },
    { VOL: '835' }
  ],
  '6445': [
    { TICKER: 'EURUSD' },
    { DTYYYYMMDD: '20030509' },
    { TIME: '142400' },
    { OPEN: '1.14886' },
    { HIGH: '1.14893' },
    { LOW: '1.14874' },
    { CLOSE: '1.14892' },
    { VOL: '889' }
  ],
  '6446': [
    { TICKER: 'EURUSD' },
    { DTYYYYMMDD: '20030509' },
    { TIME: '142500' },
    { OPEN: '1.14886' },
    { HIGH: '1.14904' },
    { LOW: '1.14886' },
    { CLOSE: '1.14904' },
    { VOL: '772' }
  ]

In order to extract at least some value from this table (`TRADING`) and this collection (`EUR/USD`), I use the following code:
await client.connect();
const testingData = client.db('Trading').collection('EUR/USD');
const getSomeCurrencyData = await testingData.findOne({'6446': { VOL: '772' }});

Questions:

  1. Why can't this query retrieve the value from the database?

  2. What query can pull at least something specific?

  3. Why using query:

    testingData.findOne('6446': [ { TICKER: 'EURUSD' }, { DTYYYYMMDD: '20030509' }, { TIME: '142500' }, { OPEN: '1.14886' }, { HIGH: '1.14904' }, { LOW: '1.14886' }, { CLOSE: '1.14904' }, { VOL: '772' } ]);

As a result, I get absolutely all the values that exist in the database and not just one specific that I specified?

CodePudding user response:

  1. First simply find a document using ID and make sure your DB connection and collection selection has worked. If that is working, then try query like this
    const getSomeCurrencyData = await testingData.findOne({'6446.VOL': '772' });

  2. If the above suggestions works, that will do

  3. Instead of passing array to find one to match, which does not work, try it like this.

    testingData.findOne({ "6446.TICKER": 'EURUSD', "6446.DTYYYYMMDD": '20030509', "6446.TIME": '142500', "6446.OPEN": '1.14886', "6446.HIGH": '1.14904', "6446.LOW": '1.14886', "6446.CLOSE": '1.14904', "6446.VOL": '772' });

  • Related