node.js найти дату в mongodb [duplicate]

Я отвечу ужасным, нарисованным рукой комиком. Второе изображение является причиной того, что result является undefined в вашем примере кода.

34
задан Guido García 30 September 2014 в 11:36
поделиться

3 ответа

44
ответ дан damphat 26 August 2018 в 17:24
поделиться
0
ответ дан KARTHIKEYAN.A 26 August 2018 в 17:24
поделиться

Вы можете использовать это, потому что я отлично работал

//lets require/import the mongodb native drivers.
var mongodb = require('mongodb');

//We need to work with "MongoClient" interface in order to connect to a mongodb server.
var MongoClient = mongodb.MongoClient;

// Connection URL. This is where your mongodb server is running.
var url = 'mongodb://localhost/klevin';

// Use connect method to connect to the Server
MongoClient.connect(url, function (err, db) {

  if (err) {
    console.log('Unable to connect to the mongoDB server. Error:', err);
  } else {
    //HURRAY!! We are connected. :)
    console.log('Connection established to', url);


    // Get the documents collection
    var collection = db.collection('frames');

    //We have a cursor now with our find criteria
    var cursor = collection.find({
      tv: 'tematv', 
      date_created: {"$gte": new Date("2015-10-01T00:00:00.000Z") , "$lt": new Date("2017-03-13T16:17:36.470Z") }});

    //We need to sort by age descending
    cursor.sort({_id: -1});

    //Limit to max 10 records
    cursor.limit(50);

    //Skip specified records. 0 for skipping 0 records.
    cursor.skip(0);


    //Lets iterate on the result
    cursor.each(function (err, doc) {

      if (err) {

        console.log(err);

      } else {

        console.log('Fetched:', doc);

        if(doc !== null){ 

        }

      }
    });


  }

});
3
ответ дан klevin 26 August 2018 в 17:24
поделиться
Другие вопросы по тегам:

Похожие вопросы: