ajclopez / mgs Goto Github PK
View Code? Open in Web Editor NEWConvert URL query parameters to MongoDB queries
License: MIT License
Convert URL query parameters to MongoDB queries
License: MIT License
I hope this message finds you well. I wanted to reach out to express my gratitude for the wonderful tool you've developed.
Question:
My entity in MongoDB:
{
"_id": {
"$oid": "666fde1af688038e64d6b58a"
},
"warehouseId": {
"$oid": "666f3a3ecf615a0f4d455411"
}
}
Code:
query:= "warehouseId=666f3a3ecf615a0f4d455411"
opts := mgs.FindOption()
result, mgsErr := mgs.MongoGoSearch(query, opts)
entity, err = collection.Find(context.TODO(), result.Filter, findOpts)
AR: entity is not found.
How can I find the entity by the query? I understand that it is not found because "warehouseId" is an ObjectId, not a string.
As a workaround, I can do this:
filter := result.Filter["$and"][0].(map[string]interface{})
filter ["warehouseId"]=primitive.ObjectIDFromHex(filter ["warehouseId"])
entity, err = collection.Find(context.TODO(), result.Filter, findOpts)
AR: entity is found.
I see that for this purpose Casters exist, but it doesn't have an OBJECT_ID caster.
Is there any other way to find the entity by the query?
If not, do you agree that this functionality is required? If you agree but don't have time to implement it, we can discuss the design here and I will prepare a PR. The easiest way would be to just add a new caster OBJECT_ID, but I think this is not the best solution because it will create a dependency on the MongoDB driver. I think an extension point can be created to avoid dependency on the driver.
Hey @ajclopez
I was going through the library and it seems very useful. However, there was one thing that I wanted to discuss which is the length of the query param in case of advanced search. Suppose there is multiple level of nested query like (((A OR B) AND (C AND D)) OR E.... where A,B,C,D,E could be filed names or queries in themselves. Thus scalability could be an issue in case of big queries. Could this be done in a POST call where there is a JSON payload (dont know how it would look like) which gets converted to BSON at the server level?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.