Работа NodeJS c JSON [требует правки]

364
17 июня 2017, 15:07

Привет ребята изучаю NodeJS + MongoDB + npm

Вот пишу ТЗ

Проект:Проект

For this section's assessment, you will fill out the functions defined in interface.js. These functions will query a collection of movies - the data in the movies collection will look like what you see in the movies.json file.

In order to complete this section's assessment, you will have to make the tests in test.js pass. To run the tests, run npm install and then npm test. You will notice the tests fail. In keeping with this section's emphasis on automation, we recommend you use npm run watch to re-run your tests every time you change the interface.js file. Once the tests succeed, npm run watch will terminate and print a "secret code" consisting of a short phrase. Copy this code into the assessment page in your browser to complete this assessment.

Пишу этот код:

exports.insert = function(db, doc, callback) { 
	db.collection('movies').insert(doc); 
  callback(null); 
}; 
 
/* 
 *  Finds all documents in the "movies" collection 
 *  whose "director" field equals the given director, 
 *  ordered by the movie's "title" field. See 
 *  http://mongodb.github.io/node-mongodb-native/2.0/api/Cursor.html#sort 
 */ 
exports.byDirector = function(db, director, callback) { 
	db.collection('movies').find({ director: 'George Lucas' }).toArray(); 
  callback(null, []); 
};

Лог ошибок:

~/Documents/home_work$ node interface.js ~/Documents/home_work$ npm test

@ test /home/ask/Documents/home_work gulp test

[15:20:10] Using gulpfile ~/Documents/home_work/gulpfile.js [15:20:10] Starting 'test'... [15:20:10] Finished 'test' after 9.89 ms

dbInterface ✓ can insert a movie 1) can query data by director 2) returns multiple results ordered by title

1 passing (272ms) 2 failing

1) dbInterface can query data by director: callback is mandatory Error at Object. (/home/ask/Documents/home_work/node_modules/mongodb-core/lib/error.js:42:24) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object. (/home/ask/Documents/home_work/node_modules/mongodb-core/index.js:2:17) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10)

2) dbInterface returns multiple results ordered by title: callback is mandatory Error at Object. (/home/ask/Documents/home_work/node_modules/mongodb-core/lib/error.js:42:24) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object. (/home/ask/Documents/home_work/node_modules/mongodb-core/index.js:2:17) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10)

Tests failed!

Объясните плиз, а то никто не отвечает, в чем дело тут?

Answer 1
exports.byDirector = function(db, dire, callback) {
    var cursor = db.movies.find({ director: dire });
    console.log(cursor);
  callback(null, []);
};
Answer 2
    exports.insert = function(db, doc, callback) {
      // TODO: implement
        db.collection('movies').insert(doc, callback);
        //callback(null);
    };
exports.byDirector = function(db, director, callback) {
    // TODO: implement
    db.collection('movies').find({"director": director}).sort({"title":1}).toArray(function(error, docs){
        if(error){
            console.log(error);
            process.exit(1);
        };
        callback(null, docs);
    });
   //callback(null, []);
};

решение

READ ALSO
Помогите найти jquery плагин пожалуйста [требует правки]

Помогите найти jquery плагин пожалуйста [требует правки]

Нужен плагин с вращающийся блоками как на этом сайте в шапке http://stranaru Помогите плз

293
Частичное применение Javascript

Частичное применение Javascript

Есть такая задача(вот тут):

995
PM2 слежение за файлами nodejs

PM2 слежение за файлами nodejs

запустил сервер через pm2 appjs --watch чтоб он следил за файлами и перезапускал сервер

280
Как узнать координату созданной метки

Как узнать координату созданной метки

Есть код с yandex api, тут круто реализовано создание меток, но вопрос

399