MongoDB深入嵌入查询(MongoDB deep embeded query)
我有这个文件
item = { "name": "string", "promotions": [{ "store_id": "key", "url": "string", "prices": [{ "cc": "string", "price_regular_in_cent": "integer", "price_sale_in_cent": "integer", "percent": "integer" }] }] }
我正在开发的一个模拟推广应用程序,用于学习NodeJS,MongoDB和Angular。 最高级别是商品信息的去处,促销是每个促销用于同一商品(每个商品可以在多个商店中),价格是每种支持货币的价格。 我创建了这个结构,因为我不想知道价格而不知道该项目,但我有一些过滤问题。
编辑:例如,如果我想过滤百分比> 50的数据库中的所有项目,我将如何在mongodb中执行此操作? 性能是否最佳?
我认为这个数据结构应该用SQL而不是NoSQL更好地实现,这是正确的吗?
I have this document
item = { "name": "string", "promotions": [{ "store_id": "key", "url": "string", "prices": [{ "cc": "string", "price_regular_in_cent": "integer", "price_sale_in_cent": "integer", "percent": "integer" }] }] }
for a demo promotion app that I'm developing to learn NodeJS, MongoDB and Angular. The top level is where the item information go, the promotions is there each promotion go for the same item (each item can be in multiple stores) and the prices is the price in each supported currency. I created this structure since I don't want to know the price without knowing the item but I have some problems with filtering.
Edit: For example if i wanted to filter all items in the db with percent >50 how would I do it in mongodb? And is the performance optimal?
And I'm thinking this data structure should be better implemented with SQL instead of NoSQL, is this correct?
原文:
最满意答案
我不太确定旋转器,但是你的SQL错了,你在每个语句中都有两个
where
子句,删除最后一个and
用一个and
替换它。 我已经更改了下面的查询,但您可以将其应用于其他查询。 希望这可以帮助替换FullFilter
public Cursor fullFilter(int finalHeat, String finalDietary, int finalTime) { return db.rawQuery("select recipe_name, _id from recipes where recipes.recipe_code in " + "(select ingredients.recipe_code from ingredients inner join kitchen on " + "kitchen.ingredient_name = ingredients.ingredient_name) and recipes.heat = "+finalHeat+" and recipes.dietary='"+finalDietary+"' and recipes.time = "+ finalTime, null); }
I amnt too sure about the spinners but your SQL is wrong, you have two
where
clauses in each of your statements, remove the lastwhere
and replace it with anand
. I have changed the query below but youll be able to apply it to the other queries. Hope this helpsReplace FullFilter
public Cursor fullFilter(int finalHeat, String finalDietary, int finalTime) { return db.rawQuery("select recipe_name, _id from recipes where recipes.recipe_code in " + "(select ingredients.recipe_code from ingredients inner join kitchen on " + "kitchen.ingredient_name = ingredients.ingredient_name) and recipes.heat = "+finalHeat+" and recipes.dietary='"+finalDietary+"' and recipes.time = "+ finalTime, null); }
相关问答
更多-
过滤用户输入(Filtering User Input)[2022-01-31]
在将字符串插入SQL查询时,使用mysql_real_escape_string() ,无论输入来自何处。 将字符串插入HTML代码时使用htmlspecialchars()或htmlentities() ,无论输入来自哪里。 在将值插入URL的查询字符串时使用urlencode() ,无论值来自何处。 如果这些数据来自用户,那么你肯定应该做这些事情,因为用户有可能试图做坏事。 但除了安全性 - 如果你想插入一个合法的字符串到一个SQL查询和字符串恰好有一个单引号字符呢? 你仍然必须逃避它。 Use mys ... -
全局设置您的ListAdapter适配器。 我相信,这将起作用。 卡迈勒 The solution provided by Luksprog worked.
-
您可以在ListView中覆盖get_queryset函数并过滤self.request.user def get_queryset(self): return Item.objects.filter(user=self.request.user) You can override get_queryset function in ListView and filter on self.request.user def get_queryset(self): return Item.obj ...
-
在你的getCount方法@Override丢失之前,只需添加它并尝试 I was getting null values in my mAdapData after filtering it 2-3 times, which was causing application to crash. To solve the problem I created the a copy of original values before filtering and if no filter was applied, ...
-
即使过滤了适配器,Adapter也应该从过滤列表中返回该项 你试过这段代码吗? vlist.setOnItemClickListener(new OnItemClickListener(){ public void onItemClick(AdapterView> a,View v,int position,long id){ Toast.makeText(getApplicationContext(),adapter.getItem ...
-
Android:Listview的东西(Android : Listview stuff)[2023-08-10]
您可以使用listview.setStackFromBottom(false)从顶部填充列表视图。 这个链接可以帮到你。 http://developer.android.com/reference/android/widget/AbsListView.html#setStackFromBottom%28boolean%29 you can use listview.setStackFromBottom(false) to fill your listview from top. this link may ... -
如何将用户的元素从web显示到android的listview(How to show elements of user from web to a listview of android)[2022-07-15]
你不需要在这里处理InutStream的事情......你已经在onResponse()中以字符串的形式获得了响应。 只需将其转换为JSON对象和进程..简而言之就是删除 InputStream ss=null; //convert response to string try{ //BufferedReader reader = new BufferedReader(new In ... -
我最终做的只是创建一个具有正确值的新适配器,并在每次需要过滤时替换旧的适配器。 What I eventually did was simply creating a new adapter with the correct values and replacing the old one every time a filtering was needed.
-
经过我们的讨论,我认为问题在于: @Override public int getCount() { return cityLists.size(); } 这使得适配器认为它的大小比正常大(因为它的大小是固定的并且在你过滤后没有改变)并且当getView() ( city= getItem(position); )正在进行时无法获得我们的边界项调用。 您应该在问题1,2和此示例中实现Filterable接口( getFilter() )。 这将在每次调用getFilter ...
-
我不太确定旋转器,但是你的SQL错了,你在每个语句中都有两个where子句,删除最后一个and用一个and替换它。 我已经更改了下面的查询,但您可以将其应用于其他查询。 希望这可以帮助 替换FullFilter public Cursor fullFilter(int finalHeat, String finalDietary, int finalTime) { return db.rawQuery("select recipe_name, _id from recipes where recipes.r ...