I come from a LAMP stack background but lately I am been interested in Node.js/Angluarjs combo. Now I am wanting to get Mongodb into the mix but I am having the hardest time getting it set up. Every tutorial I find using a different kind of stack, some are using Express.js, others Mongoose, or something else. How do I go about using angularjs HTTP service to connect to Mongo? Do I need an intermediate library like Mongoose or can I do it directly with Angular. I had set this up a while back as an experiment. I am trying to do what I am doing in this page. In this, I am storing the data in a JSON file. I want to replace that JSON file with a connection to the Mongodb. I have MongoDb installed globally for Node and I have created a data collection through the console. You can see my experiment here - http://monkbunker.com/saas/#/
And the code for the http connection I have for this can be seen here starting on line 14 https://github.com/seanandersonmke/saas/blob/master/js/main.js
Is this similar to how I can work with MongoDB? How to set up an initial connection? I have sat down several times now for hours and ended up stumped every time. Please help.
thanks.
Have a look on the following links:
Querying MongoDB with JSON / HTTP / REST Interface
Does MongoDB have a native REST interface?
There is a full python proxy solution:
http://python-eve.org/
Maybe this is helpful for you.:)
Related
I am new in web development and trying to use electron js to develop an application.
I am trying to connect my electron app to mysql database running on local machine but the issue is that electron is giving insecure resource warning and not displaying the data. I tried to turn off these security features but nothing is working, I can verify that my query is fetching the data from database.
Please see the image below:
I see a response with 3 RowDataPackage items, so it looks like turning of the security setting works.
You might want to convert the array with RowDataPackage items to an actual array by converting it to a JSON string and parse it back again.
Example:
JSON.parse(JSON.stringify(mysqlResults))
I'm building a NodeJS platform that consist of several core 'parts' (users, messages and trading signals).
So my idea is to create microservices for each of them, and it works pretty well.. But I can't get my head around how to 'join' data between the microservices (I'm a frontender originally.....)
For example, I have 3 microservices.. Each with its own MongoDB, on its own machine complete isolated.. Imagine the common situation where the messages is retrieved from a single microservice, the message has a 'user_id' and I need to get the username and profilePicture to be combined in the retrieved message object..?
I read a lot about using Redis, but it seems like a 'messaging' service to me, not much of a 'combine' service.. Can anyone help me through the darkness??
Thanks!!
I know its a very general question... But I just can't get a grip of what the 'best practice' is when combining data of multiple micro services..
I believe this can be done using kafka streams, it is a pub/sub model where you can join streams based on a common key. You can either subscribe to a topic or add a data transformation service which joins multiple streams and pushes the joined/transformed data into a new stream. All services who wants to use this data can subscribe to this new stream. I recommend you go through this link
Please, I need an expert advice on how to efficiently test a finished Node.js Application.
What I want to do is
1. I want to run the test to stimulate for example 100 users are all inserting data into a mongoDB
2. 100 users retriving records from the db
3. 100 users are maybe deleting from the database, I want to check how the system will perform in situations like that.
I read about loadtest in npm and it seems to me as a good candidate, but I don't know if I can use this to pass data(post/get) request into the database to actually, see how the system will respond to situation like 100 users all posting real data into the database.
I suppose ,loadtest helps with checking the response time of eg 20sec with maybe 40 concurrent request, which is my basic undertanding of the module, I don't know if it has other functionlities like what I am expecting to do.
Any advice or clue to go about this will be appreciated,because I wish to avoid re-engineering the wheel if possible
Thank you
You can use loadtest module.
But first you should define routes for crud processes and call
loadtest -c 10 --rps 100 http://example.com/api/collection
--rps meaning as request per second
You can get it from: https://github.com/alexfernandez/loadtest
You can use Apache JMeter to conduct load test against:
Web Application frontend - record and replay supported
Web Services
MongoDB directly
any combination of all above.
There's no reason you absolutely need to use a node.js utility to conduct load tests on node.js apps. In fact, I would suggest you use a language that supports multiple threads. With node, I'd worry about blocking the event loop, waiting on I/O and getting inaccurate results.
I recently tried vegeta and am very happy with it. You can use it as is without having to write any Golang code (although it's open source and you can modify it as you please). It supports URLs with headers and POSTs with payloads. It is written in Golang, which does support multithreading, and it even reports its latency. You can get reports in html, json and plain text right out of the box
Finally, vegeta scales well. It seems you'd like to issue POSTs, GETs and DELETEs. You can spin up an instance to do your GET loads, another one for POSTs and one for DELETES. Or you can POST a bunch of data, then DELETE the data on the same VM. When all of the VMs are done running the tests, you can look at the results separately or aggregate them.
Background: I am preparing a Meteor app for production, and in particular I am adding server logging. To do this I am using winston with the MongoDB plugin. This requires the URL to the database. These databases are different between production and development environments so I want to set it programatically.
I am trying to avoid running forking a script to run
# meteor mongo --url
I also don't have access to $MONGO_URL on the development server (it doesn't appear to be set, for instance in process.env.MONGO_URL)
I expect that there is something like below, but I couldn't find this in the documentation or via Google.
Meteor.MongoDB.getURL();
Sorry if this is something really obvious...it feels like it should be easy.
This works server side. It needs Meteor 1.0.4+ (I think. Added somewhat recently):
var collection = new Mongo.Collection("some_collection");
console.log(collection.rawCollection().db.options.url)
Keep in mind you can have multiple MongoDB's (at least at the collection level, or this is how the design is at least, anyway) so you need to query a collection for its Mongo URL.
I found the answer.
As mentioned in the question, the MONGO_URL environmental variable was undefined, but that appears to be either a misunderstanding or a bug in my IDE.
When I logged the value of process.env, I saw that MONGO_URL was indeed set, so I've used that.
In short:
process.env.MONGO_URL
I'm currently working on a meteor-Application where I want to use the list.js-JavaScript Library with Meteor.
The use-Case is that I have some data in my MongoDB on the server which I publish to the client. This data should now be rendered in a list and list.js should make it searchable.
The data is published to the client (after a short delay I get the data in the view). But it seems that the list.js-Library is run before the data hits the client. The console says that the array which is searchable only consists of "undefined".
What I've tried now is to use Template.rendered where I put my code of list.js in. But Template.rendered gets fired when the template is rendered, not when the data is receiving the client.
It seems that the data arrives too late to be grabbed by list.js.
Is there something I can do so that list.js will start when the data successfully arrived at the client? Is there something like Data.received?
Thanks in advance!
Unfortunately, that is not the meteor-way to do it. Once you get it working you will see that it lacks performance and proper reactivity.
You should instead look into using meteor's excellent reactivity and do it using template helpers, that way it will be reactive and you can scale it without performance issues.
I found a good answer to your question in the Unofficial Meteor FAQ
That describes how to know when your subscription is ready (reactive data).