Mybatis-Need to run dynamic query - mybatis

I am getting query from database.
Using that query I need to run that query and fetch data into collection.
Is there any way??

I have used resultType instead of resulmap and some how I got desired output.

Related

How to use limit and sort query in wso2esb dataservice experssion

I try to query documents and get last value from that result by using following query.
dbname.find({"name":"test"}).limit(1).sort({$natural:-1})
But in result I got all the documents which contains name as test.
Kindly let me know where I made mistake
Try please code
dbname.find({}).limit(1).sort({$natural:-1})
You can use below code also
dbname.findOne({name:'test'}).sort({$natural:-1})

Mongo Get Count While Returning Whole Documents and Should Queries

I am new to Mongo and can't seem to figure out the following after reading posts and the documentation. I am executing the following query:
db.collection.find({'name':'example name'})
Which returns 14 results. I can get the count of correctly by executing:
db.collection.find({'name':'example name'}).count()
However, I want to return the full documents and the count in a single query, similar to the way Elasticsearch does. Is there anyway to do this.
Additionally, is there any equivalence to Elasticsearch's Bool should query (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html). Essentially I would want to rank the results, so that those with attribute 'onSale=True' are returned before 'onSale=False'.
I'm not sure about your second question, whether MongoDB provides some mechanism equivalent to Elasticsearch's Bool should query.
But for your 1st question, I think you can use Cursor.
var cursor = db.collection.find({'name':'example name'});
Once you've got the cursor, you can use it for getting the count in the following way:
cursor.count()
as well as for getting the documents wrapped in an array in the following way:
cursor.toArray()
For more info on cursor, please see the below mentioned link:
http://docs.mongodb.org/manual/tutorial/iterate-a-cursor/

mongodb Temporary Collection or Aggregate on find result

I have to generate a dynamic report.
I have a complex query which returns result using db.collection.find() and has millions of records in it.
Now I want to perform aggregate operation on this result.
I tried inserting into a collection and than executing aggregate function on it using below:
db.users.find().forEach( function(myDoc) { db.usersDummy.insert(myDoc); } );
But this does not seems to be feasible to temporarily insert data and then perform aggregate operation on it.
Is there any way mongoDB supports Temporary tables or perform aggregate operation directly on find result?
As suggested by JohnnyHK i am using $match in aggregation to run the huge collection instead of creating a dummy collection
So closing this question

I am a new user of Mongo Db, please let me know the difference in executing both queries

Hi I found that the output of the two queries was same, but I want to know is there any difference in executing the query.
First:
db.collectionname.find({}).pretty()
Second:
db.offers.find().pretty()
There is no difference between these two queries.
db.collectionname.find({}).pretty()
You are not giving any query params here so the results are same like
db.collectionname.find().pretty()
In short: Both function in the same way.
1) db.collectionname.find({})
Here you are not specifying any query parameters and its just an empty document {} so it will return you all the documents present in the collection
2) db.offers.find()
Here you didn't specify any queries. So it need not even look at the parameters, it will just print you all the documents in the collection. find() short form of find({})

Spring data mongoDB GeoNear query with excluding fields

I don't know if I am doing something wrong or it is a bug.
I have the following code:
Query criteria = new Query(Criteria.where("locationTime").gte(
"date-time"));
criteria.fields().exclude("friends");
NearQuery query = NearQuery.near(point).maxDistance(maxDistance)
.num(limit).query(criteria);
GeoResults<Profile> result = mongoTemplate
.geoNear(query, Profile.class);
I am executing the query and profiles near by retrieved correctly according to distance and the "locationTime" criteria but it seems to ignore the excluded field and retrieving the profiles with their friends.
When I use simple query the exclude/include fields works perfectly.
I looked every where and could not find any resemble use-case, please let me know if i am doing something wrong.
Thanks.
There's no way to limit the fields with a geoNear command, as far as I know.
I looked into calling executeCommand to try to work around the limitations of Spring Data, but it looks like they don't even have a way to do it from the raw command.