{"size": 1052, "ext": "js", "max_stars_repo_path": "examples/eg-4-querying-options.js", "max_stars_repo_name": "anysols/anysols-odm", "max_stars_repo_stars_event_min_datetime": "2018-08-18T05:38:36.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-20T11:38:13.000Z", "max_issues_repo_path": "examples/eg-4-querying-options.js", "max_issues_repo_name": "anysols/anysols-odm", "max_issues_repo_issues_event_min_datetime": "2020-10-17T09:58:17.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-17T09:58:17.000Z", "max_forks_repo_path": "examples/eg-4-querying-options.js", "max_forks_repo_name": "anysols/anysols-odm", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 22.8695652174, "max_line_length": 67, "alphanum_fraction": 0.5418250951}
const getODM = require('./getODM');

getODM().then(async function (odm) {
  odm.defineCollection({
    name: 'teacher',
    fields: [
      {
        name: 'name',
        type: 'string'
      },
      {
        name: 'roll_no',
        type: 'integer'
      }
    ]
  });

  let teacherCollection = odm.collection('teacher');
  for (let i = 0; i < 10; i++) {
    let teacherRecord = teacherCollection.createNewRecord();
    teacherRecord.set('name', 'a' + (i + 1));
    teacherRecord.set('roll_no', i + 1);
    await teacherRecord.insert();
  }

  teacherCollection
    .find({}, { sort: { roll_no: -1 } })
    .toArray()
    .then(function (records) {
      records.forEach(async function (rec) {
        console.log(
          (await rec.getDisplayValue('name')) +
            ' :: ' +
            (await rec.getDisplayValue('roll_no'))
        );
        console.log(JSON.stringify(await rec.toObject(), null, 4));
      });
    });

  teacherCollection.count().then(function (count) {
    console.log(count);
    odm.closeConnection();
  });

});
