首页 \ 问答 \ MongoDB深入嵌入查询(MongoDB deep embeded query)

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?


原文:
更新时间:2021-12-29 22:12

最满意答案

我不太确定旋转器,但是你的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 last where and replace it with an and. I have changed the query below but youll be able to apply it to the other queries. Hope this helps

Replace 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);

}

相关问答

更多
  • 在将字符串插入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 ...
  • 您可以使用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 ...
  • 你不需要在这里处理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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。