我想使用此代码在 Firestore 中按“员工”文档的“全名”排序。
在 service.ts
getEmployees() {
return this.firestore.collection('employee').snapshotChanges();
}
Run Code Online (Sandbox Code Playgroud)
在 Component.ts 中
ngOnInit() {
this.service.getEmployees().subscribe(actionArray => {
let array = actionArray.map(item => {
return {
id: item.payload.doc.id,
...item.payload.doc.data()
};
});
....
}
Run Code Online (Sandbox Code Playgroud)
我是初学者。我需要对此代码进行哪些更改才能获得所需的输出。谢谢
我是 Flutter 和 Dart 的新手。我有以下代码:
class ItemRepository {
final Firestore _firestore = Firestore.instance;
Future<List<Item>> loadItems() async {
List<Item> itemList = [];
_firestore.collection('items').snapshots().listen((data) {
data.documents.forEach((doc){
print("------- KODE: ${doc['kode']}");
itemList.add(Item(doc['kode'], doc['name']));
});
});
return itemList;
}
}
Run Code Online (Sandbox Code Playgroud)
当我loadItems用以下代码打电话给我时:
Stream<ItemState> _mapLoadItemsToState() async* {
try {
final data = await this.repo.loadItems();
print('-------------------------------');
print(data.length);
} catch(e) {
print(e.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
它不是等待从 firebase 返回数据。我添加await了_firestore.collection('items').snapshots()但没有运气。
任何的想法?感谢您的任何建议。抱歉英语不好。
根据我读过的内容,当一个函数通过服务器运行时,所有 Firestore 规则都会被忽略。我怎样才能避免这种行为?
我尝试从本地项目调用我的测试函数。
但是每次我打电话时,我都会收到 401 错误。我不知道这里有什么麻烦,在前端我有带 api 密钥的 init 应用程序,在我有 firebase 功能admin.credential.applicationDefault();我试图通过admin.credential.cer(apiConfig),但这无济于事。
我也有环境变量GOOGLE_APPLICATION_CREDENTIALS,带有我的配置路径。
依赖关系
"firebase-admin": "~7.0.0",
"firebase-functions": "^2.2.0",
"firebase-functions-test": "^0.1.6",
Run Code Online (Sandbox Code Playgroud)
我的功能
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: "https://plan-list.firebaseio.com"
});
exports.createInviteUser = functions.https.onCall( (data, context)=> {
return data;
});
Run Code Online (Sandbox Code Playgroud)
前端功能请求
createInviteUser(email: string) {
let inviteFunction = firebase.functions().httpsCallable('createInviteUser');
inviteFunction(email)
.then((result) => {
// Read result of the Cloud Function.
console.log(result);
})
.catch(err=>{
console.log(err)
});
}
Run Code Online (Sandbox Code Playgroud)
另外,我怎么看我有所有必需的标题
12:54:58.063 …Run Code Online (Sandbox Code Playgroud) firebase firebase-authentication google-cloud-functions google-cloud-firestore
所以我有一个集合:
rootCollection -> document1 -> "field" : {"flag":true, "name" : "test1"}
rootCollection -> document2 -> "field" : {"flag":false, "name" : "test2"}
rootCollection -> document3 -> "field" : {"flag":true, "name" : "test3"}
所以我的文档包含一个字段“field1”,它是一个对象。
我想进行查询以获取我的“标志”设置为 true 的有效文档。
因此在这个例子中只返回文档 1 和 3
我怎样才能做到这一点?
UserCollection/{id}/PlayerCollection/{id}
Run Code Online (Sandbox Code Playgroud)
在最后一个文档中,有多个字段
active: true or false
dateInMillies : 123456789
return _firestore
.collection('UserCollection')
.document(userID)
.collection("PlayerCollection")
.orderBy('dateInMillis', descending: true)
.where('active', isEqualTo: true)
.snapshots();
Run Code Online (Sandbox Code Playgroud)
此代码块通过异常:
failed: Status{code=FAILED_PRECONDITION, description=The query requires an index. You can create it here: link to fix it
Run Code Online (Sandbox Code Playgroud)
但是链接已损坏,所以我必须手动完成!
所以,我去了索引选项卡,并创建了一个新的复合索引
collectionID : PlayerCollection
Fields Indexed: dateInMillis : Descending , active : Ascending
Run Code Online (Sandbox Code Playgroud)
但也没有用!
我有一个Java类,其中包含CheckForUpdate()一个返回类型为的方法String。从我发起对此方法的调用activity class。此方法将获取的String值分配给class名为的变量link。在ifblock变量内部link显示已提取String。但是在return语句中它返回null。这是为什么?
Java类:
public class method_class {
Context context;
public String link;
boolean b;
public FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
public FirebaseFirestore firestore = FirebaseFirestore.getInstance();
//constructor
public method_class(Context context)
{
this.context = context;
}
public String CheckForUpdate()
{
firestore.collection("Admin").document("appinfo")
.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if(task.isSuccessful())
{
DocumentSnapshot documentSnapshot = task.getResult();
String version = documentSnapshot.getString("version");
final String …Run Code Online (Sandbox Code Playgroud) 我有一个这样的流的组合列表;
var Ref1 = _firestore
.collectionGroup("Posts")
.where('postID', whereIn: List1)
.snapshots();
var Ref2 = _firestore
.collectionGroup("Posts")
.where('postID', whereIn: List2)
.snapshots();
var Ref3 = _firestore
.collectionGroup("Posts")
.where('postID', whereIn: List3)
.snapshots();
List<Stream<QuerySnapshot>> combineList = [Ref1, Ref2, Ref3];
Run Code Online (Sandbox Code Playgroud)
combineList通过这种方法,我合并了来自;的流。
var totalRef = Rx.combineLatest(
combineList, (list) => (list as Iterable<Iterable>).flattened);
Run Code Online (Sandbox Code Playgroud)
然后我用totalRef里面的StreamBuilder。
StreamBuilder<QuerySnapshot>(
stream: totalRef,
builder:
(BuildContext context, AsyncSnapshot asyncsnapshot) {
if (asyncsnapshot.hasError) {
return Center(
child: Text("Error"),
);
} else {
if (asyncsnapshot.hasData) {
List<DocumentSnapshot> listOfDocumentSnapshot =
asyncsnapshot.data.docs;
return ListView.builder( …Run Code Online (Sandbox Code Playgroud) [必填] 环境信息
\n**平台:Windows wsl (Ubuntu)
\n我已按照以下步骤进行操作
\nhttps://firebase.google.com/docs/functions/get-started?gen=2nd&hl=ko#about_this_tutorial
\n但它发生了
\n“无法从源加载函数定义:FirebaseError:用户代码加载失败。无法确定后端规范”
\n当我运行“firebase emulators:start”命令时
\n[错误报告]
\n当我运行“firebase emulators:start”时
\n`i emulators: Starting emulators: functions, firestore\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x9a\xa0 函数:以下模拟器未运行,从函数模拟器调用这些服务将影响生产:auth、数据库、托管、pubsub、存储
\ni firestore:Firestore 模拟器记录到 firestore-debug.log
\n\xe2\x9c\x94 firestore:Firestore 模拟器 UI websocket 正在 9150 上运行。
\ni ui:模拟器 UI 记录到 ui-debug.log
\ni 函数:正在观看“/mnt/c/Users/sunwu/Downloads/Tryagain/pythontry/functions”以获取云函数...
\n\xe2\x9c\x94 功能:使用主机上的node@18。
\n\xe2\xac\xa2 函数:无法从源加载函数定义:FirebaseError:用户代码加载失败。无法确定\n后端规范
\n …python node.js firebase google-cloud-functions google-cloud-firestore
我已经很好地遵循了以下链接中关于如何使用数据库创建 Firestore RecyclerView 的问题的答案,如何使用 Android 在 RecyclerView 中显示来自 Firestore 的数据? 现在我想获取 recyclerView 项目的项目位置(我的意思是文档 ID),我需要它的意图,以便我可以引用我的集合中的特定文档。(在新活动中)
实际的问题是我无法运行这个命令:firebase deploy --only firestore:indexes
正如您从这个链接中看到的: https: //codelabs.developers.google.com/codelabs/Friendlyeats-flutter/#12
我正在尝试通过我的 flutter 项目学习 firebase ..一般来说,我不理解这里的索引问题,如果您这样做,我将非常感谢您的努力...我添加了一个新终端,但仍然收到此错误...请帮我解决这个问题。