Feathersjs REST Query $like - rest

I have an problem to send a REST query to featherjs with the $like operator.
Table:
ID Textfield
1 andreas
Query get
localhost:3030/table?textfield[$like]=andreas
returs the row
Query get
localhost:3030/table?textfield[$like]=andrea
localhost:3030/table?textfield[$like]=andrea%
localhost:3030/table?textfield[$like]=andrea*
all this query return 0 rows
Model is Sequelize -> SQL Server
Whats wrong with the url.

I setup your example with the addition of a createdAt and updatedAt field in your test table.
I used a feathersjs Model of Sequelize -> MySQL
Table:
ID Textfield
1 andreas
I used postman to test your GET queries:
localhost:3030/table?textfield[$like]=andreas
returns:
{
"total": 1,
"limit": 20,
"skip": 0,
"data": [
{
"id": 1,
"textfield": "andreas",
"createdAt": "2017-06-05T11:33:38.000Z",
"updatedAt": null
}
]
}
localhost:3030/table?textfield[$like]=andrea%
returns:
{
"total": 1,
"limit": 20,
"skip": 0,
"data": [
{
"id": 1,
"textfield": "andreas",
"createdAt": "2017-06-05T11:33:38.000Z",
"updatedAt": null
}
]
}
localhost:3030/table?textfield[$like]=%drea%
returns:
{
"total": 1,
"limit": 20,
"skip": 0,
"data": [
{
"id": 1,
"textfield": "andreas",
"createdAt": "2017-06-05T11:33:38.000Z",
"updatedAt": null
}
]
}
The following queries should return nothing because 'andrea' can not be exactly matched in the database and the asterisk (*) is not a wild card in the SQL LIKE syntax https://www.w3schools.com/SQL/sql_like.asp :
localhost:3030/table?textfield[$like]=andrea
localhost:3030/table?textfield[$like]=andrea*
{
"total": 0,
"limit": 20,
"skip": 0,
"data": []
}

Related

MongoDb Aggregation separated array based on condition

I'm very new to mongodb. I'm trying to do an aggregation pipeline for lookup kinda like SQL left join. Given the following document's schema:
Mongo playground: https://mongoplayground.net/p/yAIwH5V2yv8
Characters:
{
"_id": 1,
"account_id": 1,
"world_id": 0,
"name": "hello"
}
Inventories:
{
"_id": 7,
"character_id": 2,
"type": "EQUIPPED"
}
Items:
{
"_id": 1,
"inventory_id": 7
}
I want to query for characters and look up inventories as well as items in inventories. I was able to achieve this however I would like to separate the inventories field in characters result document.
Current result:
{
"_id": 2,
"account_id": 1,
"world_id": 0,
"name": "hello",
"inventories: [
{
"_id": 1,
"character_id": "2",
"type": "EQUIPPED",
"items: [...]
}
]
}
What I want is based on the type of inventory I want it to be a separate field of the resulted character document something like this:
{
"_id": 2,
"account_id": 1,
"world_id": 0,
"name": "hello",
"equippedInventory: {
"_id": 1,
"character_id": "2",
"type": "EQUIPPED",
"items: [...]
},
"equipInventory: {
"_id": 2,
"character_id": "2",
"type": "EQUIP",
"items: [...]
},
}
Also, is my pipeline the best way to achieve this?

How to exclude some item when query with typeorm in Nestjs and Postgres

I want to build a query when i send username to server so i can exclude the record has the excludeUsers has the same username i sent.
Here is my data : `
"id": "f4830220-9912-4cbb-b685-edf4aaaf8fd5",
"createdAt": "2022-03-24T10:19:48.096Z",
"updatedAt": "2022-03-24T10:26:42.487Z",
"isDeleted": false,
"username": "vietphuongthoa98",
"link": "",
"type": "follow",
"current": 13456,
"target": 13556,
"totalPurchase": 100,
"purchasedPacks": [
{
"id": "fbb3079b-32c9-4c4b-a297-16741d1f5485",
"name": "Some packets",
"type": "follow",
"count": 2,
"price": 100,
"follows": 50,
"createdAt": "2022-03-23T07:18:22.898Z",
"isDeleted": false,
"updatedAt": "2022-03-23T09:49:30.192Z",
"description": "Some packages description.",
"originPrice": 0
}
],
"excludeUsers": [
{
"id": "9d8c25d2-8f03-46b3-92fa-b9489b943a56",
"deviceName": "iPhone 12 Pro Max",
"username": "hoaa.hanassii",
"platform": "ios",
"timeZone": 0,
"deviceAge": 21,
"subscribed": true,
"coins": 19600,
"subscriptionExpiration": "2022-04-27T00:00:00.000Z",
"isBlocked": false
}
]
Here is my query builder :
queryBuilder
.leftJoin('featured_user.excludeUsers', 'excludeUsers')
.andWhere('excludeUsers.username != :username', {
username: filter.username,
});
The actual query result is :
SELECT "featured_user"."id" AS "featured_user_id",
"featured_user"."tenant_id" AS "featured_user_tenant_id",
"featured_user"."created_at" AS "featured_user_created_at",
"featured_user"."updated_at" AS "featured_user_updated_at",
"featured_user"."is_deleted" AS "featured_user_is_deleted",
"featured_user"."username" AS "featured_user_username",
"featured_user"."link" AS "featured_user_link",
"featured_user"."type" AS "featured_user_type",
"featured_user"."current" AS "featured_user_current",
"featured_user"."target" AS "featured_user_target",
"featured_user"."total_purchase" AS "featured_user_total_purchase",
"featured_user"."purchased_packs" AS "featured_user_purchased_packs",
"featured_user"."user_id" AS "featured_user_user_id",
"excludeUsers"."username" AS "excludeUsers_username",
"excludeUsers"."id" AS "excludeUsers_id"
FROM "featured_users" "featured_user"
LEFT JOIN "featured_users_exclude_users_users" "featured_user_excludeUsers" ON "featured_user_excludeUsers"."featured_users_id"="featured_user"."id"
LEFT JOIN "users" "excludeUsers" ON "excludeUsers"."id"="featured_user_excludeUsers"."users_id"
WHERE "excludeUsers"."username" != $1 -- PARAMETERS: ["hoaa.hanassii"]
The problem is nothing response. Any ideal ? Thanks
can you add getMany() end of querybuilder and try
queryBuilder
.leftJoin('featured_user.excludeUsers', 'excludeUsers')
.andWhere('excludeUsers.username != :username', {
username: filter.username,
}).getMany()

Is it possible to query on a date object with the Matlab connector for MongoDB?

I have just started using MongoDB with Matlab (R2021b). Currently, I am using the mongoc class (https://ch.mathworks.com/help/database/ug/mongoc.html) to connect to my MongoDB database.
I am having issues querying on the date. I have the following collection:
{
"_id": 1,
"stock": "Stock1",
"value": 10,
"date": "2010-01-01T00:00:00.000Z"
},
{
"_id": 2,
"stock": "Stock1",
"value": 20,
"date": "2015-01-01T00:00:00.000Z"
},
{
"_id": 3,
"stock": "Stock1",
"value": 30,
"date": "2020-01-01T00:00:00.000Z"
}
And the end result would need to look as follows:
{
"_id": 2,
"stock": "Stock1",
"value": 20,
"date": "2015-01-01T00:00:00.000Z"
},
{
"_id": 3,
"stock": "Stock1",
"value": 30,
"date": "2020-01-01T00:00:00.000Z"
}
To do this, I have tried in Matlab:
conn = mongoc('localhost', 27017, database_name);
query = '{"date": {"$gte": ISODate("2015-01-01"), "$lte": ISODate("2020-01-01")}}';
res = find(conn, collection_name, 'Query', query);
However, I am getting the following error:
[Mongo Driver Error]: Got parse error at "S", position 19:
"SPECIAL_EXPECTED".
I have tried various ways of placing the quotation marks but none have proven successful. Querying with a similar string in MongoDB Compass however works. Has anyone overcome this issue or is the connector just not able to query on dates? Another solution would be to store the date in another format (int or float) and query on that, but I would like to avoid this kind of solution.
Any help would be greatly appreciated!

MongoDB - Project specific element from array (big data)

I got a big array with data in the following format:
{
"application": "myapp",
"buildSystem": {
"counter": 2361.1,
"hostname": "host.com",
"jobName": "job_name",
"label": "2361",
"systemType": "sys"
},
"creationTime": 1517420374748,
"id": "123",
"stack": "OTHER",
"testStatus": "PASSED",
"testSuites": [
{
"errors": 0,
"failures": 0,
"hostname": "some_host",
"properties": [
{
"name": "some_name",
"value": "UnicodeLittle"
},
<MANY MORE PROPERTIES>,
{
"name": "sun",
"value": ""
}
],
"skipped": 0,
"systemError": "",
"systemOut": "",
"testCases": [
{
"classname": "IdTest",
"name": "has correct representation",
"status": "PASSED",
"time": "0.001"
},
<MANY MORE TEST CASES>,
{
"classname": "IdTest",
"name": "normalized values",
"status": "PASSED",
"time": "0.001"
}
],
"tests": 8,
"time": 0.005,
"timestamp": "2018-01-31T17:35:15",
"title": "IdTest"
}
<MANY MORE TEST SUITES >,
]}
Where I can distinct three main structures with big data: TestSuites, Properties, and TestCases. My task is to sum all times from each TestSuite so that I can get the total duration of the test. Since the properties and TestCases are huge, the query cannot complete. I would like to select only the "time" value from TestSuites, but it kind of conflicts with the "time" of TestCases in my query:
db.my_tests.find(
{
application: application,
creationTime:{
$gte: start_date.valueOf(),
$lte: end_date.valueOf()
}
},
{
application: 1,
creationTime: 1,
buildSystem: 1,
"testSuites.time": 1,
_id:1
}
)
Is it possible to project only the "time" properties from TestSuites without loading the whole schema? I already tried testSuites: 1, testSuites.$.time: 1 without success. Please notice that TestSuites is an array of one element with a dictionary.
I already checked this similar post without success:
Mongodb update the specific element from subarray
Following code prints duration of each TestSuite:
query = db.my_collection.aggregate(
[
{$match: {
application: application,
creationTime:{
$gte: start_date.valueOf(),
$lte: end_date.valueOf()
}
}
},
{ $project :
{ duration: { $sum: "$testSuites.time"}}
}
]
).forEach(function(doc)
{
print(doc._id)
print(doc.duration)
}
)
Is it possible to project only the "time" properties from TestSuites
without loading the whole schema? I already tried testSuites: 1,
testSuites.$.time
Answering to your problem of prejecting only the time property of the testSuites document you can simply try projecting it with "testSuites.time" : 1 (you need to add the quotes for the dot notation property references).
My task is to sum all times from each TestSuite so that I can get the
total duration of the test. Since the properties and TestCases are
huge, the query cannot complete
As for your task, i suggest you try out the mongodb's aggregation framework for your calculations documents tranformations. The aggregations framework option {allowDiskUse : true} will also help you if you are proccessing "large" documents.

MongoDB Aggregation sum the results

Are there some good examples where I want to aggregate the following using Mongo's Aggregation Pipeline in scala.
Want to get the sum PriceAmt.
Any good URL with some great Scala examples would be of great help..
Following is the JSON that is being retrieved from MongoDB.
{
"_id": ObjectId("5269723bd516ec3a69f3639e"),
"Id": ObjectId("5269723ad516ec3a69f3639d"),
"results": [
{
"Id": "526971f5b5b8b9148404623a",
"pricingResult": {
"TxId": 0,
"PriceId": "Large_Batch_1",
"Errors": [ ],
"Disposition": [
{
"GroupId": 1,
"PriceAmt": 20,
"Status": "Priced Successfully",
"ReasonCode": 0,
"PricingMethodologyId": 2,
"Lines": [{ "Id": 1 }]
}
]
}
},
{
"ClaimId": "526971f4b5b8b91484046229",
"pricingResult": {
"TxId": 0,
"PriceId": "Large_Batch_1",
"Errors": [ ],
"Disposition": [
{
"GroupId": 1,
"PriceAmt": 20,
"Status": "Priced Successfully",
"ReasonCode": 0,
"PricingMethodologyId": 2,
"Lines": [{ "Id": 1 }]
}
]
}
}
]
}
I do not think that this is a valid question, but if you are looking for examples of aggregation framework and scala take a look at this links:
https://bhudgeons.telegr.am/blog_posts/how-to-use-the-new-mongodb-aggregation-framew
http://mongoblog.tumblr.com/post/44108207769/mongodb-aggregation-using-scala-1-2
and after this you can try to replicate some results with scala using examples from mongodb
Casbah, the official Scala driver, support the aggregation framework.
Please take a look at the documentation.