Mongodb query to node.js format - node.js

db.gpsvalues.aggregate([
{$sort:{"Timestamp":1}},
{$group:{
"_id":"$EmpID",
LastUpdated:{$last:"$Timestamp"},
Latitude:{$last:"$Latitude"},
Longitude:{$last:"$Longitude"}
}}
])
this is the query which returns expected value in mongodb. but i want to get the same values from node.js api call?
can someone tell me how to make the node.js api?
thanks in advance

You may check the mongojs node.js client which supports aggregation as mentionned in the manual.
I personnally have not used this feature yet but it should work as expected.

Related

Why does the Node.JS community generally favor NoSQL over relational databases?

Why is MongoDB usually used in conjunction with NodeJS?, Is it just coincidental or are there good engineering reasons behind this combination?
There is no direct correlation between nodejs and mongo.
In particular mongo has drivers for the following languages:
C
C++
C#
Java
Node.js
Perl
PHP
Python
Ruby
Scala
The only correlation that I can find is that using nodejs queries are more similar to the same query written in the console of mongo than other languages (below an example in nodejs and in java).
In node js:
...
db.collection('restaurants').insertOne( {
"name":"Pizza Roma",
"city":"Rome",
"country":"Italy"
});
...
In java
...
Document restaurant = new Document("name", "Pizza Roma")
.append("city", "Rome")
.append("country", "Italy");
db.getCollection("restaurants").insertOne(document);
...
The structure of MongoDB documents is JSON-like.
JSON (JavaScript Object Notation) is syntactically identical to the code for creating JavaScript objects, so creating JSON structures from objects and parsing JSON to objects is really easy in JavaScript. You can directy insert a JavaScript object structure into MongoDB.
Other than that, MongoDB has Drivers for a vast array of languages.
There is no direct relation between Node.js and Mongodb. MongoDB is a
document based database which will give data as a JSON directly and it is schema less.To develop the rapid applications now a days MEAN stack apps are very famous.Actually Node.js is not limited to MongoDB it can be connected with different databases.

Couchdb2 mango/find js api

I have noticed that all the couchdb api helpers don't implement Mango query
I have found cradle started working on it, but seems they stoped implementing, nothing on docs about it.
https://github.com/flatiron/cradle/blob/master/lib/cradle/database/mango.js
Is there a good js api that supports mango find?
Secondary: Is there a reason why no one seems to be implementing mango query, why is everyone sticking to map/reduce?
Based on the comments give, I would like to clarify my question:
I know about pouch-find, but I presume this is for local storage or local instance of pouch that could be found in browser or nodejs, but I want to find a library that I can use to query couchdb database on the server.
I have found a temporary solution for now. Im using cradle with query function
ex:
db.query({
method: 'POST',
path: "/_find",
body: {
selector:{"_id": "settings/12345" },
limit:1,
//use_index: "_all_docs"
}
}
So to further explain my setup. Im using one couchdb per user. That db will sync to browser using pouchdb, I can use pouch-find to query that synced local copy (Is this correct?).
But then I have other couch databases that are not synced, that can be accessed by many users. To query these databases I use cradle with the above example.
You can find pouchdb-find here which is in development. If there is no api helpers for Mango Query yet, it's probably because it`s new altough cloudant had this query language since a moment.

nodejs mongodb driver and GridFS

I'm using nodejs and the native mongodb driver v2.0.43 (latest as of 9/18/2015) and am having problems querying the db.fs.files collection. It is returning that fs is undefined yet I can use the mongo console and see the files that have been stored using db.fs.files.find().toArray(). Does anyone have any experience querying the db.fs.files collection via node using the mongodb driver?
thanks
Ben
Ok, after doing a better google query I found this solution: Can you use find queries on GridFS using javascript API?
The gist is you have to use 'fs.files' as the collection name.
db.collection('fs.files').find().toArray();

Data not returned from custom collection

I have a hand-made collection (mymodel) in MongoDB. I have created a sails model+controller using 'sails generate api mymodel'
I am now trying to use the sails find() method using the REST api: http://localhost:1377/mymodel, but I do not get any data returned. I have even tried to write my own end-point method and used the Waterline ORM find() method, but still don't get anything returned.
Am I missing something? Is there something more to be done?
Its a simple model, like {A:123,b:"wf"}
No specific data pieces
From mongo shell, I get the complete information
Found the problem.
If a create a collection using the name "MyModel" in MongoDB, and then create a controller+model in sails.js (sails generate api MyModel), sailsjs does not seem to use the "MyModel" collection, but rather tries to create a new collection completely in lower case ("mymodel") where all the transactions are committed.
So the trick is to create a collection in lowercase only so that sails starts using it
Not sure if this is a bug in sails.js

Looking for sequelize.js REST API generator with associations support

Is there any node.js module which would provide full REST api sequelize?
Which must follow associations, so for example if I have tables testsuites (hasMany testcases) and testcases, than the api will allow me to do: get /api/testsuite/1/testcases and it will do all the magic for me?
I checked sequelize-restful, but does not seems to work this way :(
See below libraries can help you in generating REST API with sequelize
1.https://github.com/dchester/epilogue
2.https://github.com/sequelize/sequelize-restful
Example: https://github.com/pjanaya/nodejs-express4-sequelize-restful

Resources