- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
读了很多书后,我陷入困境。我在这里发布的代码是我试图制作的商店数据库的实现。在每家商店,我们都有一些字段。我有兴趣对包含 JSON 变量的 items 数组执行一些操作。我想通过三个过滤器来过滤商品,首先是商店 ID,其次是类别 ID,最后一个过滤器是半类别 ID。
我想从前端发送数据,这意味着我提供 STOREID
、CategoryID
和 SemiCategoryID
。在后端接收到数据后,我希望根据前端提供的数据只收到相关的项目。
{
"_id": {
"$oid": "5a1844b5685cb50a38adf5bb" --> **ID of the STORE**
},
"name": "ACE",
"user_id": "59e4c41105d1f6227c1771ea",
"imageURL": "none",
"rating": 5,
"items": [
{
"name": "NirCohen",
"categoryID": "5a0c2d292235680012bd12c9",
"semiCatID": "5a0c2d5a2235680012bd12ca",
"_id": {
"$oid": "5a1958181cd8a208882a80f9"
}
},
{
"name": "he",
"categoryID": "5a0c2d292235680012bd12c9",
"semiCatID": "5a0c2d5a2235680012bd12ca",
"_id": {
"$oid": "5a1973c40e561e08b8aaf2b2"
}
},
{
"name": "a",
"categoryID": "5a0c2d292235680012bd12c9",
"semiCatID": "5a0c2d5a2235680012bd12ca",
"_id": {
"$oid": "5a197439bc1310314c4c583b"
}
},
{
"name": "aaa",
"categoryID": "5a0c2d292235680012bd12c9",
"semiCatID": "5a0c2d5a2235680012bd12ca",
"_id": {
"$oid": "5a197474558a921bb043317b"
}
},
],
"__v": 9
}
我希望后端根据查询返回过滤后的项目。问题是,我无法获得正确的查询。
非常感谢您的帮助,
提前谢谢您。
最佳答案
如果我理解正确的话,你正在做这样的事情:
Store.find({}).then(..);
如果您只想查找categoryID等于变量myCategory的商店,您可以使用以下方法过滤掉它们:
Store.find({semiCatID: myCategory}).then(..);
如果这不是您想要的,请告诉我,然后我们可以继续努力共同解决这个问题。
编辑:因此,您将从前端发送变量 StoreID
、CategoryID
和 SemiCategoryID
。在后端接收它们,并想要过滤匹配所有三个字段的数据库集合?如果是这样..那么我认为您所要做的就是更改当前的查询:
store.findOne({ _id: req.body.userID }, (err, store) => { console.log(store); });
类似于:
store.findOne({
_id: req.body.userID,
storeID: req.body.StoreID,
categoryID: req.body.CategoryID,
semiCategoryID: req.body.SemiCategoryID
}, (err, store) => { console.log(store); });
这样,您从 mongo 返回的对象必须符合前端给出的所有四个标准。
关于node.js - Mongoose如何找到特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47501445/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!