I have written the code to retrieve the data from mongodb using nodejs, but when I try to post that data using angular js, it's not working.
Here is the nodejs code:
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var ObjectId = require('mongodb').ObjectID
var url = 'mongodb://localhost:27017/shru';
var findRestaurants = function(db, callback) {
var cursor =db.collection('shruthi').find( );
cursor.each(function(err, doc) {
assert.equal(err, null);
if (doc != null) {
console.dir(doc);
} else {
callback();
}
});
};
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
findRestaurants(db, function() {
db.close();
});
});
This worked fine, I am able to retrieve the data. My database name is shru and my collection name is shruthi. This is the data what I have retrieved:
{ _id: ObjectID { _bsontype: 'ObjectID', id: 'VÍZrg¸û쮸*�?' },
name: 'shruts' }
{ _id: ObjectID { _bsontype: 'ObjectID', id: 'VÍZzg¸û쮸*Ñ' },
name: 'vani' }
When I try to post this data using mongodb its not working fine. Can anyone explain me how to do this? How do I post the above data using angular js?