小编Mr.*_*-on的帖子

使用FirestoreRecyclerAdapter(Android)进行Firestore分页

我在https://firebase.google.com/docs/firestore/query-data/query-cursors上查看了文档

我想与之合作FirestoreRecyclerAdapter

有人有针对该用例的示例工作代码吗?我有一个列表,该列表可能很长。我想设置一个限制,并通过将查询游标与limit()方法结合使用来遵循分页查询的策略。

到目前为止,这是我在ListActivity中拥有的:

     // Construct query for first 25 teachers, ordered by firstName
    firstQuery = FirebaseFirestore.getInstance()
            .collection("School").document(user.getUid())
            .collection("teachers")
            .orderBy("firstName")
            .limit(25);


    FirestoreRecyclerOptions<Teacher> options = new FirestoreRecyclerOptions.Builder<Teacher>()
            .setQuery(firstQuery, Teacher.class)
            .build();

    adapter = new FirestoreRecyclerAdapter<Teacher, TeacherHolder>(options) {
        @Override
        public void onBindViewHolder(final TeacherHolder holder, final int position, Teacher teacherItem) {
            // Bind the Teacher object to the TeacherHolder
            //progressBar.setVisibility(View.GONE);
            ....



        }
Run Code Online (Sandbox Code Playgroud)

要实施firestore docs给出的策略,下一步我该如何做。

// Construct query for first 25 cities, ordered by population
Query first = db.collection("cities")
    .orderBy("population")
    .limit(25); …
Run Code Online (Sandbox Code Playgroud)

android infinite-scroll firebase android-recyclerview google-cloud-firestore

6
推荐指数
1
解决办法
1375
查看次数

Firestore模式版本控制以及与Android应用程序的向后兼容性以防止崩溃

Firestore NOSQL是面向文档的数据库。现在,当我将数据与Firebase SDK和Android应用程序一起使用时,如何管理数据的版本控制?

例如,假设我有一个JSON模式,该模式是通过我的Android应用程序的1.0.0版本启动的。稍后的1.0.1出现了,我必须为新文档添加一些额外的字段。由于我将结构更改为具有其他信息,因此它仅适用于新文档。

因此,使用此逻辑,我可以看到我的Android应用程序必须能够处理所有版本的JSON树,如果将其用于在Firebase控制台中使用Firestore创建的该项目。但这可能是非常痛苦的权利,我不断承担着向后兼容性的沉重负担吗?有没有办法在protobuf中提供某种版本,或者将android应用发送到Firestore服务器端,以便我们能够自动执行某些操作以防止在看到新字段时android应用崩溃?

另请参阅此主题,即工程师发布的问题。您可能会遇到这种问题,因为android应用会在JSON树中发现新字段 添加新字段或更改所有Firestore文档上的结构

关于我们应该如何做的任何建议?

在node.js架构中,我们使用default-> v1.1 / update或default-> v1.0 / update处理此问题,这样我们就可以管理路由。

但是对于与Firestore NOSQL对话的android + firebase SKD->,我如何管理json模式的版本控制。

versioning android nosql firebase google-cloud-firestore

5
推荐指数
1
解决办法
389
查看次数

类型错误:req.checkBody(...).optional(...).isDate 不是函数

我在使用快速验证器时遇到了问题,特别是 isDate 函数。我已采取措施使用 expressvalidator、bodyparse、validator 模块等。所有路由仅在此之后.. 环境是 Node + Express。

问题在于使用

"req.checkBody('date_of_birth', 'Invalid date').optional({ checkFalsy: true }).isDate();" 
Run Code Online (Sandbox Code Playgroud)

我不断收到以下错误

TypeError: req.checkBody(...).optional(...).isDate is not a function
    at exports.author_create_post (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/controllers/authorController.js:47:81)
    at Layer.handle [as handle_request] (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/layer.js:95:5)
    at /Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/index.js:335:12)
    at next (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/index.js:174:3)
    at router (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/index.js:317:13)
    at /Users/svitaworld/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/index.js:335:12)
    at next (/Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/index.js:275:10)
    at /Users/mycomputer/Desktop/NodeJS/express-locallibrary-tutorial/node_modules/express/lib/router/index.js:635:15
Run Code Online (Sandbox Code Playgroud)

应用程序.js

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express express-validator

2
推荐指数
1
解决办法
7385
查看次数