Background I just started learning how to use node.js and mongodb. iv been able to create a db and connect to it / write a collection using the code below
var url = "localhost:27017/TheDatabase";
var collections = ["Location"];
var mongojs = require("mongojs")
var db = mongojs(url, collections);
var object = {
"place" : {
"address" : "123 road",
"code" : "ABC CDE",
"letters" : "AA",
"coord" : [ 99.55, -20.5 ]
},
"keyword1" : "World",
"keyword2" : "Biomech",
"keyword3" : "Spotify",
"_id" : "1"
}
db.Location.save(object);
The Problem I was unable to successfully retrieve the data from this database/collection. What i want to do is just retrieve "object" from db and display it to terminal to see i accomplished the store/retrieve correctly.
What i'v tried I'v opened mongo.exe and tried running
use TheDatabase
show collections
db.Location.find()
and was able to see the data. I'm not sure how i implement this in my node.js application.
Edit
db.Location.find(function (err, docs) {
console.log(docs);// docs is an array of all the documents in mycollection
})