Unable to query MongoDB database with node.js and Mongodb package -


I can not query my MongoDB database by node.js and mongodeb package.

I have successfully sorted 2 objects:

  var mongo = require ("mongodb"); Var host = "127.0.0.1"; Var port = mongo.Connection.DEFAULT_PORT; Var db = new mongo.db ("node-introduction", new mangu. Sir (host, port, {}), {secure: true}); Console.log (host); Db.open (function (error) {console.log ("we are connected", + host + ':' + port); db.collection ("user", {w: 1}, function (error, archive) { Console.insert ({id: "1", name: "foo bar", twitter: "flubber", email: "info@nfoobar.com"}, {w: 1}, function () {console.log ("successfully fu bar inserted");}); collection.insert ({id: "2", name: "bar foo", twitter: "bar_foo", email: "info @ Tbarfoo.com "}, {w: 1}, function () {console.log (" Successfully fired times ");});});});   

Everything is fine, there is no error but if I want to ask the item like this:

  var mongo = require ("mongodb") ; Var host = "127.0.0.1"; Var port = mongo.Connection.DEFAULT_PORT; Var db = new mongo.db ("node-intro", new mangu. Sir (host, port, {}), {secure: wrong}); Console.log (host); Db.open (function (error) {console.log ("we are connected", + host + ':' + port); // is the type of archive table db.collection ("user", function (error, archive) {Console.log ("We have a collection"); collection.find ({"id": "1"}, function (error, cursor) {cursor.toArray (function (error, user) {if (users.length == 0) {console.log ("no user was found");} else {console.log ("found a user", user [0]);}})}});});});   

Then I received the following error:

  127.0.0.1 We are connected to NaN: 27017 We have the archive /path/to/query.js: 14 If (users.length == 0) {^ TypeError: property of zero can not be read 'length'   

So what do I understand that the variable is user tap and can not do it Find any match but I do not know why this is what iam doing wrong?

found a solution Monogram was not running How could I include MongoDB without any errors?

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -