1到多个firebase查询(1 to many firebase query)
我试图在firebase中创建一个到多个数据结构。 我的两个对象看起来像这样
category: { cat1: { name: 'Category 1' }, cat2: { name: 'Category 2' } } products: { product1: { name: 'Product 1', categories: { cat1: true } }, product2: { name: 'Product 2', categories: { cat1: true, cat2: true } } }
现在我如何查询这些数据以获得所有类别的product2? 我试过这个让我得到所需的数据,但它看起来效率低下,并不符合文档似乎建议你这样做的方式....
var ref = new Firebase("https://<my-firebase-url>/products/product2"); var catRef = new Firebase("https://<my-firebase-url>/category"); ref.once('value', function(snap) { var result = snap.val(); Object.keys(result.categories).map(key => { catRef.child(key).once('value', function(category){ ... //add category to array etc } } }
文档建议使用child_added事件,但是当我想要整个列表而不仅仅是添加子项时,这有什么用呢? ( https://www.firebase.com/docs/web/guide/structuring-data.html ):
// List the names of all Mary's groups var ref = new Firebase("https://docs-examples.firebaseio.com/web/org"); // fetch a list of Mary's groups ref.child("users/mchen/groups").on('child_added', function(snapshot) { // for each group, fetch the name and print it String groupKey = snapshot.key(); ref.child("groups/" + groupKey + "/name").once('value', function(snapshot) { System.out.println("Mary is a member of this group: " + snapshot.val()); }); });
I am trying to create a 1 to many data structure in firebase. My two objects look like this
category: { cat1: { name: 'Category 1' }, cat2: { name: 'Category 2' } } products: { product1: { name: 'Product 1', categories: { cat1: true } }, product2: { name: 'Product 2', categories: { cat1: true, cat2: true } } }
Now how exactly would I query this data to get say product2 with all categories? I have tried this which gets me back the required data but it seems inefficient and doesn't match how the docs seem to suggest you do it....
var ref = new Firebase("https://<my-firebase-url>/products/product2"); var catRef = new Firebase("https://<my-firebase-url>/category"); ref.once('value', function(snap) { var result = snap.val(); Object.keys(result.categories).map(key => { catRef.child(key).once('value', function(category){ ... //add category to array etc } } }
The docs suggest to use the child_added event but how does this make sense when I want the entire list not just when a child is added? (https://www.firebase.com/docs/web/guide/structuring-data.html):
// List the names of all Mary's groups var ref = new Firebase("https://docs-examples.firebaseio.com/web/org"); // fetch a list of Mary's groups ref.child("users/mchen/groups").on('child_added', function(snapshot) { // for each group, fetch the name and print it String groupKey = snapshot.key(); ref.child("groups/" + groupKey + "/name").once('value', function(snapshot) { System.out.println("Mary is a member of this group: " + snapshot.val()); }); });
原文:https://stackoverflow.com/questions/38954249
最满意答案
Have a look at
How to set order of repositories in Maven settings.xml
and
After Maven Bug (MNG-4400) was fixed, artifacts are resolved in defined repository order.
相关问答
更多-
deploy:deploy-file是正确的。 将它与-Durl=http://repo:port/path , -DrepositoryId=server-whatever 。 您的settings.xml需要包含
server-whatever demo demo -
渐变交替mvn安装(Gradle alternate to mvn install)[2024-03-07]
SDK /的build.gradle: apply plugin: "maven" group = "foo" version = "1.0" 例如/的build.gradle: repositories { mavenLocal() } dependencies { compile "foo:sdk:1.0" } $ sdk> gradle安装 $ example> gradle build sdk/build.gradle: apply plugin: "maven" grou ... -
肯,好问题。 关于差异的“最终指南”应该更加明确。 “安装”和“部署”在构建中服务于两个不同的目的。 “安装”是指在本地存储库中安装工件的过程。 “部署”是指将工件部署到远程存储库的过程。 例: 当我在机器上运行一个大型的多模块项目时,我通常会运行“mvn install”。 这将在我的本地存储库中安装所有生成的二进制软件工件(通常为JAR)。 然后,当我在构建中构建单个模块时,Maven将从本地存储库检索依赖项。 在安装快照或发布版本的时候,我将运行“mvn deploy”。 运行此操作将尝试将文件部署到 ...
-
看一下 如何在Maven settings.xml中设置存储库的顺序 和 Maven存储库查找顺序 Maven Bug(MNG-4400)修复后,工件在已定义的存储库顺序中解析。 Have a look at How to set order of repositories in Maven settings.xml and Maven repository lookup order After Maven Bug (MNG-4400) was fixed, artifacts are resolved i ...
-
你只是在命令行上运行它? 你可以使用nohup( http://linux.101hacks.com/unix/nohup-command/ ) nohup mvn exec:java -Dexec.mainClass & Are you just running it on the command line? You can use nohup (http://linux.101hacks.com/unix/nohup-command/) nohup mvn exec:java -Dexec.mainC ...
-
这是设计的。 tomcat的官方文档:run说: 在开发war项目时,通常会构建war并将其部署到已安装的Tomcat实例。 这耗费时间和资源,并且需要时间在本地安装实例。 运行mojo让你有机会通过在Maven构建中的嵌入式Tomcat实例中运行你的战争来保存它。 所以我必须在服务器视图中启动已安装的Tomcat实例,然后maven插件使用此服务器实例进行tomcat:run之外的其他目标。 This is by design. The official doc for tomcat:run says: ...
-
通过遵循关于如何安装maven插件的不同的oracle指导来解决这个问题。 本指南似乎在安装Web逻辑插件方面做得更好。 http://docs.oracle.com/middleware/1213/wls/WLPRG/maven.htm 引用oracle安装指南的相关部分。 Install the Oracle Maven sync plug-in and run the push goal: Change directory to ORACLE_HOME\oracle_common\plugins\m ...
-
你确定这不是服务器端问题吗? 我部署了一些使用Webdav(通过HTTPS)和第一次(创建目录)的库,它工作。 Pom.xml应该包含分发服务器的描述。
RepoId Name of the Maven repository dav:https://thewebdavurl/ fals ... -
版本51对应于以下消息中的JDK 7: org/eclipse/jetty/maven/plugin/JettyRunMojo: Unsupported major.minor version 51.0 看起来Jetty 9是使用JDK 7构建的,源设置为1.7 。 您可以尝试安装JDK 7来运行它。 Okay I got it working. It seemed that Maven was using Java 1.6 instead of 1.7 as it should. I opened te ...
-
你需要关闭路径中的%。 路径:%JAVA_HOME%\ bin;%M2_HOME%\ bin; ... 代替 路径:%JAVA_HOME \ bin;%M2_HOME \ bin; ... YOu need to close the % in the path. PATH : %JAVA_HOME%\bin;%M2_HOME%\bin;... instead of PATH : %JAVA_HOME\bin;%M2_HOME\bin;...